diff --git a/config/config.toml b/config/config.toml index e69de29..dac64e3 100644 --- a/config/config.toml +++ b/config/config.toml @@ -0,0 +1,7 @@ +# config.toml +host = "127.0.0.1" +port = "3000" +# TMDbApiKey is required +tmdbApiKey = "" +dbName = "racer.db" +uploadFolder = "/home/rouggy/torrents/rtorrent/Race" diff --git a/internal/config/config.go b/internal/config/config.go index fbaa2b1..9852d06 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,6 +1,7 @@ package config import ( + "bytes" "errors" "log" "os" @@ -35,6 +36,7 @@ func writeConfig(configPath string, configFile string) error { } // check if config exists, if not create it + host := "0.0.0.0" if _, err := os.Stat(cfgPath); errors.Is(err, os.ErrNotExist) { f, err := os.Create(cfgPath) @@ -46,9 +48,23 @@ func writeConfig(configPath string, configFile string) error { defer f.Close() // setup text template to inject variables into - _, err = template.New("config").Parse(configTemplate) + tmpl, err := template.New("config").Parse(configTemplate) if err != nil { - log.Println("Could not create config file:", err) + return err + } + + tmplVars := map[string]string{ + "host": host, + } + + var buffer bytes.Buffer + if err = tmpl.Execute(&buffer, &tmplVars); err != nil { + return err + } + + if _, err = f.WriteString(buffer.String()); err != nil { + log.Printf("error writing contents to file: %v %q", configPath, err) + return err } return f.Sync() diff --git a/racer.db.db b/racer.db.db new file mode 100644 index 0000000..0b5b713 Binary files /dev/null and b/racer.db.db differ