- Added sample default config (needs manual updating)

- Reworked service and webapi config to Viper unmarshalling
- Added Pretty Printers to config
This commit is contained in:
2021-08-22 14:46:48 +02:00
parent 9a31bbc912
commit 7b93ff425d
6 changed files with 54 additions and 12 deletions

View File

@@ -1,6 +1,9 @@
package webapi
import (
"encoding/json"
"log"
"github.com/spf13/viper"
)
@@ -19,5 +22,13 @@ func SetConfigDefaults() {
}
func LoadConfig() {
C.ListenAddress = viper.GetString("WebAPI.ListenAddress")
viper.UnmarshalKey("WebAPI", &C)
}
func (obj *config) PrettyPrint() string {
s, err := json.MarshalIndent(obj, "", " ")
if err != nil {
log.Fatalf("Failed to pretty print WebAPI Config via JSON: %v", err)
}
return string(s)
}

View File

@@ -63,4 +63,8 @@ func handleUpdate(w http.ResponseWriter, r *http.Request) {
log.Printf("Request PW: %s, Config PW: %s", ur.Password, v.GetString("password"))
fmt.Fprintln(w, "Unmarshalled userconfig:")
fmt.Fprintln(w, uc.PrettyPrint())
fmt.Fprintln(w, "WebAPI Config:")
fmt.Fprintln(w, C.PrettyPrint())
fmt.Fprintln(w, "Service Config:")
fmt.Fprintln(w, service.C.PrettyPrint())
}