Mercurial > gemma
changeset 1366:a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 27 Nov 2018 10:42:27 +0100 |
parents | da7ee82ad5d6 |
children | 5d4bfe4fa13c |
files | pkg/config/config.go |
diffstat | 1 files changed, 77 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/config/config.go Tue Nov 27 09:03:27 2018 +0100 +++ b/pkg/config/config.go Tue Nov 27 10:42:27 2018 +0100 @@ -30,35 +30,79 @@ // This is not part of the persistent config. var configFile string -func DBHost() string { return viper.GetString("db-host") } -func DBPort() uint { return uint(viper.GetInt32("db-port")) } -func DBName() string { return viper.GetString("db-name") } -func DBUser() string { return viper.GetString("db-user") } +// DBHost is the hostname of the database. +func DBHost() string { return viper.GetString("db-host") } + +// DBPort is the port of the database. +func DBPort() uint { return uint(viper.GetInt32("db-port")) } + +// DBName is the name of the database. +func DBName() string { return viper.GetString("db-name") } + +// DBUser is the name of the user to connect to the database. +func DBUser() string { return viper.GetString("db-user") } + +// DBPassword is the password to connect to the database. func DBPassword() string { return viper.GetString("db-password") } -func DBSSLMode() string { return viper.GetString("db-ssl") } +// DBSSLMode selects the SSL mode to encrypt the connection to the database. +func DBSSLMode() string { return viper.GetString("db-ssl") } + +// SessionStore is the path to the session store. +// If empty the session store is kept in memory only. func SessionStore() string { return viper.GetString("sessions") } -func Web() string { return viper.GetString("web") } +// Web is the root folder of the served web content. +func Web() string { return viper.GetString("web") } + +// WebHost is the host to bind the web server to. func WebHost() string { return viper.GetString("host") } -func WebPort() uint { return uint(viper.GetInt32("port")) } + +// WebPort is the port to bind the web server to. +func WebPort() uint { return uint(viper.GetInt32("port")) } + +// MailHost is the server of the SMTP server. +func MailHost() string { return viper.GetString("mail-host") } -func MailHost() string { return viper.GetString("mail-host") } -func MailPort() uint { return uint(viper.GetInt32("mail-port")) } -func MailUser() string { return viper.GetString("mail-user") } +// MailPort is the port of the SMTP server. +func MailPort() uint { return uint(viper.GetInt32("mail-port")) } + +// MailUser is the user to connect to the SMTP server. +func MailUser() string { return viper.GetString("mail-user") } + +// MailPassword is the password of the user to connect to the SMTP server. func MailPassword() string { return viper.GetString("mail-password") } -func MailFrom() string { return viper.GetString("mail-from") } -func MailHelo() string { return viper.GetString("mail-helo") } + +// MailFrom is the sender in the 'from' header in mails send. +func MailFrom() string { return viper.GetString("mail-from") } +// MailHelo is the helo message send to the SMTP server. +func MailHelo() string { return viper.GetString("mail-helo") } + +// AllowedOrigins is a list of allowed host for CORS headers. func AllowedOrigins() []string { return viper.GetStringSlice("allowed-origins") } -func Proxies(key string) map[string]interface{} { return viper.GetStringMap(key) } +// GeoServerURL is the URL of the GeoServer used by gemma to serve map data. +func GeoServerURL() string { return viper.GetString("geoserver-url") } + +// GeoServerUser is the adminstrative user to connect to the GeoServer. +func GeoServerUser() string { return viper.GetString("geoserver-user") } + +// GeoServerPassword is the password of the adminstrative user +// to connect to the GeoServer. +func GeoServerPassword() string { return viper.GetString("geoserver-password") } -func GeoServerURL() string { return viper.GetString("geoserver-url") } -func GeoServerUser() string { return viper.GetString("geoserver-user") } -func GeoServerPassword() string { return viper.GetString("geoserver-password") } -func GeoServerClean() bool { return viper.GetBool("geoserver-clean") } +// GeoServerClean is a flag to indicate that the GeoServer setup for +// gemma should be freshly created at boot time. +// This is useful in case of gemma update. +// If false the only missing parts are added to the GeoServer setup. +// This should be the default mode when running gemma after an update +// as it reduces the pressure on the GeoServer and enables faster +// rebooting. +func GeoServerClean() bool { return viper.GetBool("geoserver-clean") } +// TmpDir is the path where to store temporary files. +// If left empty the system default for temporary files is used. func TmpDir() string { return viper.GetString("tmp-dir") } var ( @@ -69,6 +113,12 @@ proxyPrefix string ) +// ProxyKey is a crytographic key to sign the URLs generated by the proxy. +// Use this to ensure that only known URLs are reachable over the proxy. +// If left blank a random key is generated a gemma boot time. +// Setting this value in the configuration will allow browsing proxy +// generated URL across gemma reboot. +// Use a strong secret key here (like pwgen -s 20). func ProxyKey() []byte { fetchKey := func() { if proxyKey == nil { @@ -85,6 +135,10 @@ return proxyKey } +// ProxyPrefix is the prefix used in generated URLs by the proxy. +// It defauls to http://${WebHost}:${WebPort}". +// You may need to set this if you run gemma behind a proxy +// on a specific domain. func ProxyPrefix() string { fetchPrefix := func() { if proxyPrefix == "" { @@ -95,6 +149,7 @@ return proxyPrefix } +// RootCmd is cobra command to be bound th the cobra/viper infrastructure. var RootCmd = &cobra.Command{ Use: "gemma", Short: "gemma is a server for waterway monitoring and management", @@ -175,6 +230,7 @@ configReady bool ) +// Ready tells if the configuration is ready to use.. func Ready() { configCond.L.Lock() defer configCond.L.Unlock() @@ -182,6 +238,10 @@ configCond.Broadcast() } +// WaitReady blocks until the configuration is ready to use. +// Call this if you have a go routine that needs configuration +// support. This guarantees that the initialization is done +// before accessing the configuration data. func WaitReady() { configCond.L.Lock() defer configCond.L.Unlock()