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
cfgparse(cfgloc)
}
func cfgparse (cfgloc string){
log.Print("Opening: ", cfgloc)
cfgf, err := os.Open(cfgloc)
defer cfgf.Close()
file, err := os.Open(cfgloc)
defer file.Close()
if err != nil {
log.Fatal(err)
}
cfgfb := bufio.NewScanner(cfgf)
cfgfb.Split(bufio.ScanLines)
for res := cfgfb.Scan();res;res = cfgfb.Scan() {
state, body := cfgparseline(cfgfb.Text())
filebuf := bufio.NewScanner(file)
filebuf.Split(bufio.ScanLines)
for res := filebuf.Scan();res;res = filebuf.Scan() {
state, body := cfgparseline(filebuf.Text())
log.Print(state, body)
}
err = cfgfb.Err()
err = filebuf.Err()
if err != nil {
log.Fatal(err)
}
}
func cfgparseline(buf string) (uint8, string){
// State options
// 0 - Init