Compare commits

..

2 Commits

Author SHA1 Message Date
91709e65bd defer closing file when loading data 2022-03-20 02:20:13 +01:00
0e5a3d7361 fix using / in path 2022-03-20 02:18:46 +01:00
3 changed files with 25 additions and 24 deletions

View File

@@ -57,7 +57,7 @@ Default: `auth.toml`
### --data-path
Will define where stored data is put (i.e. IP addresses for subdomains). All records will be saved here every second if they have been changed and when the application gets shut down.
Type: `string`
Default: `./`
Default: `.`
## Routes
### `/`

View File

@@ -89,29 +89,30 @@ func loadFile(ty string, currentDomain *domain) {
f, err := os.Open(filePath)
if err != nil {
color.Warnf("Could not load file for domain %s: %s\n", currentDomain.Root, err)
} else {
log.Printf("Reading file: %s", filePath)
scanner := bufio.NewScanner(f)
lineCounter := 0
for scanner.Scan() {
lineCounter++
currentLine := scanner.Text()
cols := strings.Split(currentLine, "\t")
if len(cols) < 2 {
color.Warnf("Error reading line %d of ipv4 addresses for domain %s: too few columns\n", lineCounter, currentDomain.Root)
continue
}
if ty == IPV4_FILE {
currentDomain.Ipv4[cols[0]] = cols[1]
} else if ty == IPV6_FILE {
currentDomain.Ipv6[cols[0]] = cols[1]
}
}
color.Infof("Read file: %s\n", filePath)
return
}
f.Close()
defer f.Close()
log.Printf("Reading file: %s", filePath)
scanner := bufio.NewScanner(f)
lineCounter := 0
for scanner.Scan() {
lineCounter++
currentLine := scanner.Text()
cols := strings.Split(currentLine, "\t")
if len(cols) < 2 {
color.Warnf("Error reading line %d of ipv4 addresses for domain %s: too few columns\n", lineCounter, currentDomain.Root)
continue
}
if ty == IPV4_FILE {
currentDomain.Ipv4[cols[0]] = cols[1]
} else if ty == IPV6_FILE {
currentDomain.Ipv6[cols[0]] = cols[1]
}
}
color.Infof("Read file: %s\n", filePath)
}
func Init(dataPath string) {

View File

@@ -17,7 +17,7 @@ import (
var (
configFile = flag.String("config-file", "conf.toml", "Path to configuration file")
authFile = flag.String("auth-file", "auth.toml", "Path to authentication file")
dataPath = flag.String("data-path", "./", "Where to save data")
dataPath = flag.String("data-path", ".", "Where to save data")
enableDebugMode = flag.Bool("enable-debug-mode", false, "Enables debug mode, will output a list of all registered records on the index page of the HTTP server")
)