Skip to content

Commit

Permalink
Fixed config file not creating
Browse files Browse the repository at this point in the history
  • Loading branch information
tsunagatteru committed Apr 20, 2023
1 parent 4b59cb3 commit 1e0fd46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions cmd/inn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"io/fs"
"log"
"os"

"github.com/tsunagatteru/ishiki-no-nagare/options"
Expand All @@ -21,6 +22,14 @@ func main() {
}
os.Mkdir(dataPath, 0755)
os.Mkdir(dataPath+"images/", 0755)
if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) {
file, err := os.Create(dataPath + "config.yml")
if err != nil {
log.Fatalln("Unable to create file:", err)
}
defer file.Close()
}

config := options.GetCfg(dataPath)
server.Run(resources, variables, config)
}
3 changes: 2 additions & 1 deletion options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package options

import (
"fmt"
"log"

"github.com/fsnotify/fsnotify"
flag "github.com/spf13/pflag"
Expand Down Expand Up @@ -30,7 +31,7 @@ func GetCfg(dataPath string) *viper.Viper {
config.AddConfigPath(dataPath)
err := config.ReadInConfig()
if err != nil {
fmt.Println("error reading config file: %w", err)
log.Fatalln("error reading config file: %w", err)
}
config.WriteConfig()
config.OnConfigChange(func(e fsnotify.Event) {
Expand Down

0 comments on commit 1e0fd46

Please sign in to comment.