package main

import (
	"bufio"
	"flag"
	"log"
	"os"
)

type host struct {
	name     string
	protocol string
	endpoint string
}

var hosts []host

// readHosts reads in hosts from a file and populates hosts []host.
func readHosts() {
	f, err := os.Open(filename)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		hosts = append(hosts, host{name: scanner.Text()})
		// TODO: parse for urls, set host.protocol and host.endpoint. net/url.Parse seems like a good fit.
	}
	if err := scanner.Err(); err != nil {
		log.Printf("error reading hosts from %s:%s\n", filename, err)
	}
}

var filename string

func init() {
	// Check for '-f' flag for host file
	flag.StringVar(&filename, "f", "hosts", "File with hosts and urls to check.")
	flag.Parse()
}

func main() {
	// if an entry is a url, send a GET request
	// if an entry is a hostname, send an ICMP ping
	// TODO: host method for GET
	// TODO: host method for ICMP
	// TODO: figure out how to represent responses.
	// TODO: store responses in google sheets.
	// TODO: cache writes to google sheets if network is unavailable.
	// TODO: rewrite host request methods as goroutines.
}

package main

import (
	"bufio"
	"flag"
	"log"
	"os"
)

type host struct {
	name     string
	protocol string
	endpoint string
}

var hosts []host

// readHosts reads in hosts from a file and populates hosts []host.
func readHosts() {
	f, err := os.Open(filename)
	if err != nil {
		log.Println(err)
	}
	defer f.Close()

	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		hosts = append(hosts, host{name: scanner.Text()})
		// TODO: parse for urls, set host.protocol and host.endpoint
	}
	if err := scanner.Err(); err != nil {
		log.Printf("error reading hosts from %s:%s\n", filename, err)
	}
}

var filename string

func init() {
	// Check for '-f' flag for host file
	flag.StringVar(&filename, "f", "hosts", "File with hosts and urls to check.")
	flag.Parse()
}

func main() {
	// if an entry is a url, send a GET request
	// if an entry is a hostname, send an ICMP ping
	// TODO: host method for GET
	// TODO: host method for ICMP
	// TODO: figure out how to represent responses.
	// TODO: store responses in google sheets.
}

--- 
+++ 
@@ -19,14 +19,14 @@
 func readHosts() {
 	f, err := os.Open(filename)
 	if err != nil {
-		log.Println(err)
+		log.Fatal(err)
 	}
 	defer f.Close()
 
 	scanner := bufio.NewScanner(f)
 	for scanner.Scan() {
 		hosts = append(hosts, host{name: scanner.Text()})
-		// TODO: parse for urls, set host.protocol and host.endpoint
+		// TODO: parse for urls, set host.protocol and host.endpoint. net/url.Parse seems like a good fit.
 	}
 	if err := scanner.Err(); err != nil {
 		log.Printf("error reading hosts from %s:%s\n", filename, err)
@@ -48,4 +48,6 @@
 	// TODO: host method for ICMP
 	// TODO: figure out how to represent responses.
 	// TODO: store responses in google sheets.
+	// TODO: cache writes to google sheets if network is unavailable.
+	// TODO: rewrite host request methods as goroutines.
 }
Change fail to open hosts file to log.Fatal()
