bug fix
This commit is contained in:
15
src/main.go
15
src/main.go
@@ -36,7 +36,7 @@ type ConfigTOML struct {
|
|||||||
Config struct {
|
Config struct {
|
||||||
HttpPort int `toml:"httpPort"`
|
HttpPort int `toml:"httpPort"`
|
||||||
CacheDir string `toml:"cacheDir"`
|
CacheDir string `toml:"cacheDir"`
|
||||||
AutoDeleteCacheDir bool `toml:"dutoDeleteCacheDir"`
|
AutoDeleteCacheDir bool `toml:"dayToDeleteCacheDir"`
|
||||||
DaysToDelete int `toml:"daysToDelete"`
|
DaysToDelete int `toml:"daysToDelete"`
|
||||||
DataDir string `toml:"dataDir"`
|
DataDir string `toml:"dataDir"`
|
||||||
} `toml:"Config"`
|
} `toml:"Config"`
|
||||||
@@ -98,14 +98,13 @@ func main() {
|
|||||||
|
|
||||||
out, _ := exec.Command("uname", "-s").Output()
|
out, _ := exec.Command("uname", "-s").Output()
|
||||||
if uname := strings.TrimSpace(string(out)); uname == "OpenTTY" {
|
if uname := strings.TrimSpace(string(out)); uname == "OpenTTY" {
|
||||||
PacketsDir = "/mnt"
|
PacketsDir = "/mnt/packets"
|
||||||
} else {
|
} else {
|
||||||
PacketsDir = "/etc/packets"
|
PacketsDir = "/etc/packets"
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := os.Stat(filepath.Join(PacketsDir, "config.toml"))
|
_, err := os.Stat(filepath.Join(PacketsDir, "config.toml"))
|
||||||
if err == os.ErrNotExist {
|
if os.IsNotExist(err) {
|
||||||
fmt.Println("can't find config.toml, generating a blank one")
|
fmt.Println("can't find config.toml, generating a default one")
|
||||||
|
|
||||||
cfg.Config.HttpPort = 9123
|
cfg.Config.HttpPort = 9123
|
||||||
cfg.Config.AutoDeleteCacheDir = false
|
cfg.Config.AutoDeleteCacheDir = false
|
||||||
@@ -113,19 +112,21 @@ func main() {
|
|||||||
cfg.Config.DataDir = "/opt/packets"
|
cfg.Config.DataDir = "/opt/packets"
|
||||||
cfg.Config.DaysToDelete = -1
|
cfg.Config.DaysToDelete = -1
|
||||||
|
|
||||||
|
os.MkdirAll(PacketsDir, 0644)
|
||||||
file, err := os.Create(filepath.Join(PacketsDir, "config.toml"))
|
file, err := os.Create(filepath.Join(PacketsDir, "config.toml"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
encoder := toml.NewEncoder(file)
|
encoder := toml.NewEncoder(file)
|
||||||
|
|
||||||
if err := encoder.Encode(cfg); err != nil {
|
if err := encoder.Encode(cfg); err != nil {
|
||||||
|
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
fmt.Println("Operation Sucess!")
|
fmt.Println("Operation Sucess!")
|
||||||
|
|
||||||
file.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = toml.DecodeFile(filepath.Join(PacketsDir, "config.toml"), &cfg)
|
_, err = toml.DecodeFile(filepath.Join(PacketsDir, "config.toml"), &cfg)
|
||||||
|
|||||||
Reference in New Issue
Block a user