2024-01-01 15:27:59 -06:00
|
|
|
package main
|
|
|
|
|
2024-01-18 01:33:07 -06:00
|
|
|
import (
|
2024-01-01 15:27:59 -06:00
|
|
|
"bufio"
|
2024-01-18 01:33:07 -06:00
|
|
|
"log"
|
|
|
|
"os"
|
2024-01-01 15:27:59 -06:00
|
|
|
"strings"
|
|
|
|
|
2024-01-18 01:33:07 -06:00
|
|
|
"go.wit.com/lib/gui/cloudflare"
|
2024-01-01 15:27:59 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
var configfile string = ".config/wit/cloudflare"
|
|
|
|
|
|
|
|
func saveConfig() {
|
|
|
|
log.Println("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func readConfig() {
|
|
|
|
homeDir, err := os.UserHomeDir()
|
|
|
|
if err != nil {
|
|
|
|
log.Println("searchPaths() error. exiting here?")
|
|
|
|
}
|
|
|
|
filename := homeDir + "/" + configfile
|
|
|
|
log.Println("filename =", filename)
|
|
|
|
|
|
|
|
readFileLineByLine(filename)
|
|
|
|
// os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
// readFileLineByLine opens a file and reads through each line.
|
|
|
|
func readFileLineByLine(filename string) error {
|
|
|
|
// Open the file.
|
|
|
|
file, err := os.Open(filename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
log.Println("readFileLineByLine() =", filename)
|
|
|
|
|
|
|
|
// Create a new Scanner for the file.
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
|
|
|
|
// Read through each line using scanner.
|
|
|
|
for scanner.Scan() {
|
|
|
|
var newc *cloudflare.ConfigT
|
|
|
|
newc = new(cloudflare.ConfigT)
|
|
|
|
|
|
|
|
line := scanner.Text()
|
|
|
|
parts := strings.Fields(line)
|
|
|
|
|
2024-01-18 01:33:07 -06:00
|
|
|
if len(parts) < 4 {
|
2024-01-01 15:27:59 -06:00
|
|
|
log.Println("readFileLineByLine() SKIP =", parts)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
newc.Domain = parts[0]
|
|
|
|
newc.ZoneID = parts[1]
|
|
|
|
newc.Auth = parts[2]
|
|
|
|
newc.Email = parts[3]
|
|
|
|
|
|
|
|
cloudflare.Config[parts[0]] = newc
|
|
|
|
log.Println("readFileLineByLine() =", newc.Domain, newc.ZoneID, newc.Auth, newc.Email)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for errors during Scan.
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|