From 901f42582807baa27da26e7088d8924827f5a7d1 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Sat, 31 Jan 2015 19:23:05 -0800 Subject: [PATCH] Changed interface for Hostfile so names are better - Dump to export - Read to import --- hostess.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/hostess.go b/hostess.go index e52bef1..9866da6 100644 --- a/hostess.go +++ b/hostess.go @@ -61,17 +61,22 @@ func (h *Hostfile) Read() string { return h.data } -func coalesce(hostnames []Hostname) string { +func Dump(hostnames []Hostname) string { return "" } -func writeHosts(path, contents string) { +func DumpToFile(path string) { } var line_parser = regexp.MustCompile(``) func parseLine(line string) (Hostname, error) { + // 1. Split on # to discard comments. + // 2. Split on first space to find the IP + // 3. Split remainder of line on whitespace to find + // domain names + // 4. Validate the IP (maybe -- could be ipv4 or ipv6) hostname := Hostname{} if false { return hostname, errors.New("Can't parse hostname") @@ -79,11 +84,15 @@ func parseLine(line string) (Hostname, error) { return hostname, nil } -func parseHosts(hostfile string) []Hostname { +func Read(hostfile string) []Hostname { var hosts = make([]Hostname, 0) return hosts } +func ReadFile(path string) { + +} + func (h *Hostfile) Add(host Hostname) { h.Hosts[host.Domain] = &host } @@ -114,19 +123,9 @@ func GetHostsPath() string { return path } -func getCommand() string { - return os.Args[1] -} - -func getArgs() []string { - return os.Args[2:] -} - func Hostess() { hostfile := NewHostfile(GetHostsPath()) hostfile.Read() hostfile.Add(Hostname{"localhost", "127.0.0.1", true}) hostfile.Enable("localhost") - - fmt.Println(getArgs()) }