2021-08-15 19:37:11 +00:00
|
|
|
package webapi
|
|
|
|
|
|
|
|
import (
|
2021-08-22 12:46:48 +00:00
|
|
|
"encoding/json"
|
|
|
|
"log"
|
|
|
|
|
2021-08-15 19:37:11 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
type config struct {
|
|
|
|
ListenAddress string
|
|
|
|
}
|
|
|
|
|
|
|
|
var C config
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
SetConfigDefaults()
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetConfigDefaults() {
|
|
|
|
viper.SetDefault("WebAPI.ListenAddress", ":8080")
|
|
|
|
}
|
|
|
|
|
|
|
|
func LoadConfig() {
|
2021-08-22 12:46:48 +00:00
|
|
|
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)
|
2021-08-15 19:37:11 +00:00
|
|
|
}
|