wip: integration between cmd.go and config.go
This commit is contained in:
parent
b67955ab28
commit
0123d9d37c
3 changed files with 93 additions and 58 deletions
84
config.go
84
config.go
|
@ -1,5 +1,7 @@
|
|||
package main
|
||||
|
||||
//TODO move flag declarations here
|
||||
|
||||
const (
|
||||
ViperAPIPort string = "api.port"
|
||||
FlagAPIPort string = "api-port"
|
||||
|
@ -16,6 +18,11 @@ const (
|
|||
DefaultDBDatabase string = "bottin"
|
||||
DescriptionDBDatabase string = "Postgres database"
|
||||
|
||||
ViperDBSSLMode string = "db.sslmode"
|
||||
FlagDBSSLMode string = "db-sslmode"
|
||||
DefaultDBSSLMode string = "prefer"
|
||||
DescriptionDBSSLMode string = "Postgres sslmode"
|
||||
|
||||
ViperDBHost string = "db.host"
|
||||
FlagDBHost string = "db-host"
|
||||
DefaultDBHost string = "db"
|
||||
|
@ -36,40 +43,40 @@ const (
|
|||
DefaultDBUser string = "bottin"
|
||||
DescriptionDBUser string = "Postgres user"
|
||||
|
||||
viperWebUser string = "web.user"
|
||||
flagWebUser string = "web-user"
|
||||
defaultWebUser string = "bottin"
|
||||
descriptionWebUser string = "Web client basic auth user"
|
||||
ViperWebUser string = "web.user"
|
||||
FlagWebUser string = "web-user"
|
||||
DefaultWebUser string = "bottin"
|
||||
DescriptionWebUser string = "Web client basic auth user"
|
||||
|
||||
viperWebPassword string = "web.password"
|
||||
flagWebPassword string = "web-password"
|
||||
defaultWebPassword string = "bottin"
|
||||
descriptionWebPassword string = "Web client basic auth password"
|
||||
ViperWebPassword string = "web.password"
|
||||
FlagWebPassword string = "web-password"
|
||||
DefaultWebPassword string = "bottin"
|
||||
DescriptionWebPassword string = "Web client basic auth password"
|
||||
|
||||
viperWebPort string = "web.port"
|
||||
flagWebPort string = "web-port"
|
||||
defaultWebPort int = 2312
|
||||
descriptionWebPort string = "Web client port"
|
||||
ViperWebPort string = "web.port"
|
||||
FlagWebPort string = "web-port"
|
||||
DefaultWebPort int = 2312
|
||||
DescriptionWebPort string = "Web client port"
|
||||
|
||||
viperWebAPIHost string = "api.host"
|
||||
flagWebAPIHost string = "api-host"
|
||||
defaultWebAPIHost string = "api"
|
||||
descriptionWebAPIHost string = "Target API server host"
|
||||
ViperWebAPIHost string = "api.host"
|
||||
FlagWebAPIHost string = "api-host"
|
||||
DefaultWebAPIHost string = "api"
|
||||
DescriptionWebAPIHost string = "Target API server host"
|
||||
|
||||
viperWebAPIKey string = "api.key"
|
||||
flagWebAPIKey string = "api-key"
|
||||
defaultWebAPIKey string = "bottin"
|
||||
descriptionWebAPIKey string = "Target API server key"
|
||||
ViperWebAPIKey string = "api.key"
|
||||
FlagWebAPIKey string = "api-key"
|
||||
DefaultWebAPIKey string = "bottin"
|
||||
DescriptionWebAPIKey string = "Target API server key"
|
||||
|
||||
viperWebAPIPort string = "api.port"
|
||||
flagWebAPIPort string = "api-port"
|
||||
defaultWebAPIPort int = 1312
|
||||
descriptionWebAPIPort string = "Target API server port"
|
||||
ViperWebAPIPort string = "api.port"
|
||||
FlagWebAPIPort string = "api-port"
|
||||
DefaultWebAPIPort int = 1312
|
||||
DescriptionWebAPIPort string = "Target API server port"
|
||||
|
||||
viperWebAPIProtocol string = "api.protocol"
|
||||
flagWebAPIProtocol string = "api-protocol"
|
||||
defaultWebAPIProtocol string = "http"
|
||||
descriptionWebAPIProtocol string = "Target API server protocol (http/https)"
|
||||
ViperWebAPIProtocol string = "api.protocol"
|
||||
FlagWebAPIProtocol string = "api-protocol"
|
||||
DefaultWebAPIProtocol string = "http"
|
||||
DescriptionWebAPIProtocol string = "Target API server protocol (http/https)"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
|
@ -97,3 +104,24 @@ type Config struct {
|
|||
} `yaml:"api"`
|
||||
} `yaml:"web"`
|
||||
}
|
||||
|
||||
// DefaultConfig returns a Config filled with the default values from the
|
||||
// `Default*` constants defined in this file.
|
||||
func DefaultConfig() (cfg Config) {
|
||||
cfg.API.Port = DefaultAPIPort
|
||||
cfg.API.Key = DefaultAPIKey
|
||||
cfg.DB.Database = DefaultDBDatabase
|
||||
cfg.DB.Host = DefaultDBHost
|
||||
cfg.DB.SSLMode = DefaultDBSSLMode
|
||||
cfg.DB.Password = DefaultDBPassword
|
||||
cfg.DB.Port = DefaultDBPort
|
||||
cfg.DB.User = DefaultDBUser
|
||||
cfg.Web.User = DefaultWebUser
|
||||
cfg.Web.Password = DefaultWebPassword
|
||||
cfg.Web.Port = DefaultWebPort
|
||||
cfg.Web.API.Host = DefaultWebAPIHost
|
||||
cfg.Web.API.Key = DefaultWebAPIKey
|
||||
cfg.Web.API.Port = DefaultWebAPIPort
|
||||
cfg.Web.API.Protocol = DefaultWebAPIProtocol
|
||||
return
|
||||
}
|
||||
|
|
Reference in a new issue