update
This commit is contained in:
parent
aa39764a99
commit
b38fcd2942
@ -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"
|
@ -1,6 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -35,6 +36,7 @@ func writeConfig(configPath string, configFile string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if config exists, if not create it
|
// check if config exists, if not create it
|
||||||
|
host := "0.0.0.0"
|
||||||
if _, err := os.Stat(cfgPath); errors.Is(err, os.ErrNotExist) {
|
if _, err := os.Stat(cfgPath); errors.Is(err, os.ErrNotExist) {
|
||||||
|
|
||||||
f, err := os.Create(cfgPath)
|
f, err := os.Create(cfgPath)
|
||||||
@ -46,9 +48,23 @@ func writeConfig(configPath string, configFile string) error {
|
|||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
// setup text template to inject variables into
|
// setup text template to inject variables into
|
||||||
_, err = template.New("config").Parse(configTemplate)
|
tmpl, err := template.New("config").Parse(configTemplate)
|
||||||
if err != nil {
|
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()
|
return f.Sync()
|
||||||
|
BIN
racer.db.db
Normal file
BIN
racer.db.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user