changeset 385:3cfab707f909

Added config parameters for GeoServer.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 13 Aug 2018 11:17:56 +0200
parents af82a8989b44
children 999f4f83a072
files config/config.go
diffstat 1 files changed, 58 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/config/config.go	Mon Aug 13 11:03:30 2018 +0200
+++ b/config/config.go	Mon Aug 13 11:17:56 2018 +0200
@@ -36,63 +36,79 @@
 
 func ExternalWFSs() map[string]interface{} { return viper.GetStringMap("external-wfs") }
 
+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 GeoServerTables() []string { return viper.GetStringSlice("geoserver-tables") }
+
 var RootCmd = &cobra.Command{
 	Use:   "gemma",
 	Short: "gemma is a server for waterway monitoring and management",
 }
 
+var allowedOrigins = []string{
+	// TODO: Fill me!
+}
+
+var geoTables = []string{
+	// TODO: Fill me!
+}
+
 func init() {
 	cobra.OnInitialize(initConfig)
 	fl := RootCmd.PersistentFlags()
 	fl.StringVarP(&configFile, "config", "c", "", "config file (default is $HOME/.gemma.toml)")
 
-	fl.StringP("dbhost", "H", "localhost", "host of the database")
-	fl.UintP("dbport", "P", 5432, "port of the database")
-	fl.StringP("dbname", "d", "gemma", "name of the database")
-	fl.StringP("dbssl", "S", "prefer", "SSL mode of the database")
-
-	fl.StringP("sessions", "s", "", "path to the sessions file")
-
-	fl.StringP("web", "w", "", "path to the web files")
-	fl.StringP("host", "o", "localhost", "host of the web app")
-	fl.UintP("port", "p", 8000, "port of the web app")
-
-	fl.String("service-user", "postgres", "user to do service tasks")
-	fl.String("service-password", "", "password of user to do service tasks")
-
-	fl.String("mail-host", "localhost", "server to send mail with")
-	fl.Uint("mail-port", 465, "port of server to send mail with")
-	fl.String("mail-user", "gemma", "user to send mail with")
-	fl.String("mail-password", "", "password of user to send mail with")
-	fl.String("mail-from", "noreplay@localhost", "from line of mails")
-	fl.String("mail-helo", "localhost", "name of server to send mail from.")
-
-	fl.StringSlice("allowed-origins", []string{"foo.org"}, "allow access for remote origins")
-
 	vbind := func(name string) { viper.BindPFlag(name, fl.Lookup(name)) }
 
-	vbind("dbhost")
-	vbind("dbport")
-	vbind("dbname")
-	vbind("dbssl")
-
-	vbind("sessions")
-
-	vbind("web")
-	vbind("host")
-	vbind("port")
+	str := func(name, value, usage string) {
+		fl.String(name, value, usage)
+		vbind(name)
+	}
+	strP := func(name, shorthand, value, usage string) {
+		fl.StringP(name, shorthand, value, usage)
+		vbind(name)
+	}
+	ui := func(name string, value uint, usage string) {
+		fl.Uint(name, value, usage)
+		vbind(name)
+	}
+	uiP := func(name, shorthand string, value uint, usage string) {
+		fl.UintP(name, shorthand, value, usage)
+		vbind(name)
+	}
+	strSl := func(name string, value []string, usage string) {
+		fl.StringSlice(name, value, usage)
+		vbind(name)
+	}
 
-	vbind("service-user")
-	vbind("service-password")
+	strP("dbhost", "H", "localhost", "host of the database")
+	uiP("dbport", "P", 5432, "port of the database")
+	strP("dbname", "d", "gemma", "name of the database")
+	strP("dbssl", "S", "prefer", "SSL mode of the database")
+
+	strP("sessions", "s", "", "path to the sessions file")
+
+	strP("web", "w", "", "path to the web files")
+	strP("host", "o", "localhost", "host of the web app")
+	uiP("port", "p", 8000, "port of the web app")
+
+	str("service-user", "postgres", "user to do service tasks")
+	str("service-password", "", "password of user to do service tasks")
 
-	vbind("mail-host")
-	vbind("mail-port")
-	vbind("mail-user")
-	vbind("mail-password")
-	vbind("mail-from")
-	vbind("mail-helo")
+	str("mail-host", "localhost", "server to send mail with")
+	ui("mail-port", 465, "port of server to send mail with")
+	str("mail-user", "gemma", "user to send mail with")
+	str("mail-password", "", "password of user to send mail with")
+	str("mail-from", "noreplay@localhost", "from line of mails")
+	str("mail-helo", "localhost", "name of server to send mail from.")
 
-	vbind("allowed-origins")
+	strSl("allowed-origins", allowedOrigins, "allow access for remote origins")
+
+	str("geoserver-url", "http://localhost:8080/geoserver", "URL to GeoServer")
+	str("geoserver-user", "admin", "GeoServer user")
+	str("geoserver-password", "geoserver", "GeoServer password")
+	strSl("geoserver-tables", geoTables, "tables to publish with GeoServer")
 }
 
 func initConfig() {