diff options
| author | Jeff Carr <[email protected]> | 2023-12-21 09:39:33 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2023-12-21 09:39:33 -0600 |
| commit | 597e7d2638e458e531f42c3d6b08006764eb34ca (patch) | |
| tree | 479e7c2c172be49f97247cb6580a60c3a30b150c | |
| parent | bb662ccd82cbf07742896075127920493c1a4aaf (diff) | |
move code into the cloudflare package
| -rw-r--r-- | examples/cloudflare/config.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/examples/cloudflare/config.go b/examples/cloudflare/config.go new file mode 100644 index 0000000..a65ad25 --- /dev/null +++ b/examples/cloudflare/config.go @@ -0,0 +1,71 @@ +// This is a simple example +package main + +import ( + "os" + "log" + "bufio" + "strings" + + "go.wit.com/control-panel-dns/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) + + if (len(parts) < 4) { + 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 +} |
