Moved config parsing to a seperate function

This will allow for easier looping later on when this can be run as a
daemon
stable
Justin Reichardt 2021-12-09 15:12:44 -06:00
parent 154bd3dfe8
commit ad1410410b
1 changed files with 12 additions and 8 deletions

View File

@ -53,24 +53,28 @@ func main() {
} }
// Parse Config // Parse Config
cfgparse(cfgloc)
}
func cfgparse (cfgloc string){
log.Print("Opening: ", cfgloc) log.Print("Opening: ", cfgloc)
cfgf, err := os.Open(cfgloc) file, err := os.Open(cfgloc)
defer cfgf.Close() defer file.Close()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
cfgfb := bufio.NewScanner(cfgf) filebuf := bufio.NewScanner(file)
cfgfb.Split(bufio.ScanLines) filebuf.Split(bufio.ScanLines)
for res := cfgfb.Scan();res;res = cfgfb.Scan() { for res := filebuf.Scan();res;res = filebuf.Scan() {
state, body := cfgparseline(cfgfb.Text()) state, body := cfgparseline(filebuf.Text())
log.Print(state, body) log.Print(state, body)
} }
err = cfgfb.Err() err = filebuf.Err()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }
func cfgparseline(buf string) (uint8, string){ func cfgparseline(buf string) (uint8, string){
// State options // State options
// 0 - Init // 0 - Init