From b38fcd29427afccc389b43c5feb4383abcc7e2ab Mon Sep 17 00:00:00 2001 From: ROuGGy Date: Thu, 7 Dec 2023 23:20:47 +0800 Subject: [PATCH] update --- config/config.toml | 7 +++++++ internal/config/config.go | 20 ++++++++++++++++++-- racer.db.db | Bin 0 -> 24576 bytes 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 racer.db.db 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 0000000000000000000000000000000000000000..0b5b713d5b4cb4f461840e632105bb4687dabf0a GIT binary patch literal 24576 zcmeI%&u`N(6bJBR>spDb5}b0OlI2sYWe9$YXv)?-2}%W9at zY4&o<&a=JT>~ipzW5c@V-R+nOM{Q()eDZ2|IvJ8@5o$i?ibP5*nM%n8PYFx36yZ$qB@eYr z&48_LkP_dFv{-VNCQ&xdZhJGjzMswLg2f9;J~B01Fx4B}@4Hk>rA&4&WJ|vO=)qvn zC*$)88NV5g%*tkkxm4-R6QsF)lOo#SKsU0%BQGBA%~Ud%5O9-1E6K0Vwj zXXV3Q2I`tC``0IS%jtIQA1AAJD3(>l@n9m)r92X`^vwl-B5^X^lf(3eOw_EB*)>YB3=%D}q-8s2-DXU7B)c@|6Do`q{I&dFaOm0SG_< z0uX=z1Rwwb2tWV=5P(391@Qb|z{}fB*y_009U<00Izz00atwTiFrs|IrT+ zfB*y_009U<00Izz00bZafm#dT{eP{?i!TQO2tWV=5P$##AOHafKmY;|$OZ8JAB_M3 X2tWV=5P$##AOHafKmY;|sK3B(rw@|v literal 0 HcmV?d00001