From be9eff8ba8c5ebe1e43a89761a963c755795936c Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 11:37:16 +0100 Subject: [PATCH] add tags to structs --- graph-explorer/pkg/config/config.go | 58 ++++++++++++++--------------- graph-explorer/pkg/config/env.go | 12 ++++++ 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index 8b50a3115..3a52e857d 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -10,59 +10,59 @@ import ( // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `mapstructure:"addr"` + Token string `mapstructure:"token"` + Pprof bool `mapstructure:"pprof"` + Zpages bool `mapstructure:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string - Namespace string + Addr string `mapstructure:"addr"` + Root string `mapstructure:"root"` + Namespace string `mapstructure:"namespace"` } // Server configures a server. type Server struct { - Version string - Name string + Version string `mapstructure:"version"` + Name string `mapstructure:"name"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `mapstructure:"enabled"` + Type string `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Collector string `mapstructure:"collector"` + Service string `mapstructure:"service"` } // GraphExplorer defines the available graph-explorer configuration. type GraphExplorer struct { - ClientID string - Issuer string - GraphURLBase string - GraphURLPath string + ClientID string `mapstructure:"client_id"` + Issuer string `mapstructure:"issuer"` + GraphURLBase string `mapstructure:"graph_url_base"` + GraphURLPath string `mapstructure:"graph_url_path"` } // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - HTTP HTTP - Server Server - Tracing Tracing - GraphExplorer GraphExplorer + File string `mapstructure:"file"` + Log Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Server Server `mapstructure:"server"` + Tracing Tracing `mapstructure:"tracing"` + GraphExplorer GraphExplorer `mapstructure:"graph_explorer"` Context context.Context Supervised bool diff --git a/graph-explorer/pkg/config/env.go b/graph-explorer/pkg/config/env.go index f36e9d83a..e5dd435e8 100644 --- a/graph-explorer/pkg/config/env.go +++ b/graph-explorer/pkg/config/env.go @@ -8,6 +8,18 @@ type mapping struct { // structMappings binds a set of environment variables to a destination on cfg. func structMappings(cfg *Config) []mapping { return []mapping{ + { + EnvVars: []string{"GRAPH_EXPLORER_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_LOG_COLOR", "OCIS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, { EnvVars: []string{"GRAPH_EXPLORER_LOG_FILE", "OCIS_LOG_FILE"}, Destination: &cfg.Log.File,