- 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:
@@ -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)
|
||||
}
|
||||
|
@@ -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())
|
||||
}
|
||||
|
Reference in New Issue
Block a user