Mercurial > gemma
annotate pkg/config/config.go @ 5711:2dd155cc95ec revive-cleanup
Fix all revive issue (w/o machine generated stuff).
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 20 Feb 2024 22:22:57 +0100 |
parents | a826d84485c8 |
children |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
2 // without warranty, see README.md and license for details. |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
6 // |
2901
da1d063ee085
improve cmd/gemma/gemma --help
Bernhard Reiter <bernhard@intevation.de>
parents:
2639
diff
changeset
|
7 // Copyright (C) 2018, 2019 by via donau |
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
1317
5443f5c9154c
Added missing authors names in Go files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
13 // * Bernhard E. Reiter <bernhard.reiter@intevation.de> |
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
14 |
5711
2dd155cc95ec
Fix all revive issue (w/o machine generated stuff).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5610
diff
changeset
|
15 // Package config holds the configuration of the gemma server. |
28
714787accd26
Fetch database connection string parts from configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 package config |
714787accd26
Fetch database connection string parts from configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
18 import ( |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
19 "crypto/sha256" |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
20 "fmt" |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
21 lg "log" |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
22 "sync" |
2639
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
23 "time" |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
24 |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
25 homedir "github.com/mitchellh/go-homedir" |
3161
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3104
diff
changeset
|
26 |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
27 "github.com/spf13/cobra" |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
28 "github.com/spf13/viper" |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
29 |
414
c1047fd04a3a
Moved project specific Go packages to new pkg folder.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
408
diff
changeset
|
30 "gemma.intevation.de/gemma/pkg/common" |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
31 "gemma.intevation.de/gemma/pkg/log" |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
32 ) |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
33 |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
34 // This is not part of the persistent config. |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
35 var configFile string |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
36 |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
37 // DBHost is the hostname of the database. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
38 func DBHost() string { return viper.GetString("db-host") } |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
39 |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
40 // DBPort is the port of the database. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
41 func DBPort() uint { return uint(viper.GetInt32("db-port")) } |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
42 |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
43 // DBName is the name of the database. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
44 func DBName() string { return viper.GetString("db-name") } |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
45 |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
46 // DBUser is the name of the user to connect to the database. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
47 func DBUser() string { return viper.GetString("db-user") } |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
48 |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
49 // DBPassword is the password to connect to the database. |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
50 func DBPassword() string { return viper.GetString("db-password") } |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
51 |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
52 // DBSSLMode selects the SSL mode to encrypt the connection to the database. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
53 func DBSSLMode() string { return viper.GetString("db-ssl") } |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
54 |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
55 // SessionStore is the path to the session store. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
56 // If empty the session store is kept in memory only. |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
57 func SessionStore() string { return viper.GetString("sessions") } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
58 |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
59 // Web is the root folder of the served web content. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
60 func Web() string { return viper.GetString("web") } |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
61 |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
62 // WebHost is the host to bind the web server to. |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
63 func WebHost() string { return viper.GetString("host") } |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
64 |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
65 // WebPort is the port to bind the web server to. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
66 func WebPort() uint { return uint(viper.GetInt32("port")) } |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
67 |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
68 // MailHost is the server of the SMTP server. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
69 func MailHost() string { return viper.GetString("mail-host") } |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
385
diff
changeset
|
70 |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
71 // MailPort is the port of the SMTP server. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
72 func MailPort() uint { return uint(viper.GetInt32("mail-port")) } |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
73 |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
74 // MailUser is the user to connect to the SMTP server. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
75 func MailUser() string { return viper.GetString("mail-user") } |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
76 |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
77 // MailPassword is the password of the user to connect to the SMTP server. |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
78 func MailPassword() string { return viper.GetString("mail-password") } |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
79 |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
80 // MailFrom is the sender in the 'from' header in mails send. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
81 func MailFrom() string { return viper.GetString("mail-from") } |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
82 |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
83 // MailHelo is the helo message send to the SMTP server. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
84 func MailHelo() string { return viper.GetString("mail-helo") } |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
85 |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
86 // AllowedOrigins is a list of allowed host for CORS headers. |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
87 func AllowedOrigins() []string { return viper.GetStringSlice("allowed-origins") } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
88 |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
89 // GeoServerURL is the URL of the GeoServer used by gemma to serve map data. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
90 func GeoServerURL() string { return viper.GetString("geoserver-url") } |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
91 |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
92 // GeoServerUser is the adminstrative user to connect to the GeoServer. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
93 func GeoServerUser() string { return viper.GetString("geoserver-user") } |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
94 |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
95 // GeoServerPassword is the password of the adminstrative user |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
96 // to connect to the GeoServer. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
97 func GeoServerPassword() string { return viper.GetString("geoserver-password") } |
335
bd292a554b6e
Made gemma a WFS proxy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
98 |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
99 // GeoServerClean is a flag to indicate that the GeoServer setup for |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
100 // gemma should be freshly created at boot time. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
101 // This is useful in case of gemma update. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
102 // If false the only missing parts are added to the GeoServer setup. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
103 // This should be the default mode when running gemma after an update |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
104 // as it reduces the pressure on the GeoServer and enables faster |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
105 // rebooting. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
106 func GeoServerClean() bool { return viper.GetBool("geoserver-clean") } |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
107 |
4624
209b10f7bb2c
Add config for GeoServer database session startup SQL
Tom Gottfried <tom@intevation.de>
parents:
3582
diff
changeset
|
108 // GeoServerStartupSQL can be used to add SQL commands to GeoServers database |
209b10f7bb2c
Add config for GeoServer database session startup SQL
Tom Gottfried <tom@intevation.de>
parents:
3582
diff
changeset
|
109 // session start script. See |
209b10f7bb2c
Add config for GeoServer database session startup SQL
Tom Gottfried <tom@intevation.de>
parents:
3582
diff
changeset
|
110 // https://docs.geoserver.org/stable/en/user/data/database/sqlsession.html |
209b10f7bb2c
Add config for GeoServer database session startup SQL
Tom Gottfried <tom@intevation.de>
parents:
3582
diff
changeset
|
111 // Note that the commands will be executed as the user configured as 'db-user'. |
209b10f7bb2c
Add config for GeoServer database session startup SQL
Tom Gottfried <tom@intevation.de>
parents:
3582
diff
changeset
|
112 func GeoServerStartupSQL() string { |
209b10f7bb2c
Add config for GeoServer database session startup SQL
Tom Gottfried <tom@intevation.de>
parents:
3582
diff
changeset
|
113 return viper.GetString("geoserver-startup-sql") |
209b10f7bb2c
Add config for GeoServer database session startup SQL
Tom Gottfried <tom@intevation.de>
parents:
3582
diff
changeset
|
114 } |
209b10f7bb2c
Add config for GeoServer database session startup SQL
Tom Gottfried <tom@intevation.de>
parents:
3582
diff
changeset
|
115 |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
116 // TmpDir is the path where to store temporary files. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
117 // If left empty the system default for temporary files is used. |
958
2818ad6c7d32
Started with import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
874
diff
changeset
|
118 func TmpDir() string { return viper.GetString("tmp-dir") } |
2818ad6c7d32
Started with import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
874
diff
changeset
|
119 |
3104
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2906
diff
changeset
|
120 // PublishedConfig is a name of a JSON file where extra configuration is stored |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2906
diff
changeset
|
121 // to be served to to the web client. |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2906
diff
changeset
|
122 func PublishedConfig() string { return viper.GetString("published-config") } |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2906
diff
changeset
|
123 |
3161
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3104
diff
changeset
|
124 // SOAPTimeout is the timeout till a SOAP request is canceled. |
3169
9128fdeba3bc
Consmetics: Adjusted config.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3162
diff
changeset
|
125 func SOAPTimeout() time.Duration { return viper.GetDuration("soap-timeout") } |
3161
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3104
diff
changeset
|
126 |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4624
diff
changeset
|
127 // ReportPath is a path where report templates are stored. |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4624
diff
changeset
|
128 func ReportPath() string { return viper.GetString("report-path") } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4624
diff
changeset
|
129 |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
130 // LogFile is the path to the log file. |
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
131 func LogFile() string { return viper.GetString("log-file") } |
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
132 |
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
133 // LogLevel is the log level of the application. |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5490
diff
changeset
|
134 func LogLevel() log.Level { return log.ParseLogLevel(viper.GetString("log-level")) } |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
135 |
5610
a826d84485c8
Use token server to fetch token for ERDMS requests.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
136 // TokenURL is the ERDMS token service URL. |
a826d84485c8
Use token server to fetch token for ERDMS requests.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
137 func TokenURL() string { return viper.GetString("token-url") } |
a826d84485c8
Use token server to fetch token for ERDMS requests.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
138 |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
139 var ( |
2639
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
140 proxyKeyOnce sync.Once |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
141 proxyKey []byte |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
142 proxyPrefixOnce sync.Once |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
143 proxyPrefix string |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
144 externalURLOnce sync.Once |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
145 externalURL string |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
146 sessionTimeoutOnce sync.Once |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
147 sessionTimeout time.Duration |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
148 ) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
149 |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
150 // ProxyKey is a crytographic key to sign the URLs generated by the proxy. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
151 // Use this to ensure that only known URLs are reachable over the proxy. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
152 // If left blank a random key is generated a gemma boot time. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
153 // Setting this value in the configuration will allow browsing proxy |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
154 // generated URL across gemma reboot. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
155 // Use a strong secret key here (like pwgen -s 20). |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
156 func ProxyKey() []byte { |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
157 fetchKey := func() { |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
158 if proxyKey == nil { |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
159 key := []byte(viper.GetString("proxy-key")) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
160 if len(key) == 0 { |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
161 key = common.GenerateRandomKey(64) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
162 } |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
163 hash := sha256.New() |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
164 hash.Write(key) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
165 proxyKey = hash.Sum(nil) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
166 } |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
167 } |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
168 proxyKeyOnce.Do(fetchKey) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
169 return proxyKey |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
170 } |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
171 |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
172 // ProxyPrefix is the prefix used in generated URLs by the proxy. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
173 // You may need to set this if you run gemma behind a proxy |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
174 // on a specific domain. |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
175 func ProxyPrefix() string { |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
176 fetchPrefix := func() { |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
177 if proxyPrefix == "" { |
1644
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
178 if proxyPrefix = viper.GetString("proxy-prefix"); proxyPrefix == "" { |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
179 proxyPrefix = fmt.Sprintf("http://%s:%d", WebHost(), WebPort()) |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
180 } |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
181 } |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
182 } |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
183 proxyPrefixOnce.Do(fetchPrefix) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
184 return proxyPrefix |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
185 } |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
186 |
1644
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
187 // ExternalURL is the URL to find this server from the outside. |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
188 func ExternalURL() string { |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
189 fetchExternal := func() { |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
190 if externalURL == "" { |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
191 if externalURL = viper.GetString("external-url"); externalURL == "" { |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
192 externalURL = fmt.Sprintf("http://%s:%d", WebHost(), WebPort()) |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
193 } |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
194 } |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
195 } |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
196 externalURLOnce.Do(fetchExternal) |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
197 return externalURL |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
198 } |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
199 |
2639
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
200 // SessionTimeout is the duration until a session expires if not renewed |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
201 func SessionTimeout() time.Duration { |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
202 fetchTimeout := func() { |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
203 if sessionTimeout == 0 { |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
204 sessionTimeout = viper.GetDuration("session-timeout") |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
205 if sessionTimeout <= 0 { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
206 lg.Println("warn: non-positive session-timeout configured.") |
2639
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
207 } |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
208 } |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
209 } |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
210 sessionTimeoutOnce.Do(fetchTimeout) |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
211 return sessionTimeout |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
212 } |
0db742c7813d
Make session timeout configurable
Tom Gottfried <tom@intevation.de>
parents:
2181
diff
changeset
|
213 |
2906
ae678f7cf938
Removed irritatting parts from config doc strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2901
diff
changeset
|
214 // SchemaDirs are the root directories where to find schema files. |
2181
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1644
diff
changeset
|
215 func SchemaDirs() string { return viper.GetString("schema-dirs") } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1644
diff
changeset
|
216 |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
217 // RootCmd is cobra command to be bound th the cobra/viper infrastructure. |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
218 var RootCmd = &cobra.Command{ |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
219 Use: "gemma", |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
220 Short: "gemma is a server for waterway monitoring and management", |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
221 } |
119
29e56c342c9f
Added first middleware for JWT token extraction. TODO: Add second one to check against logged in users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
28
diff
changeset
|
222 |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
223 var allowedOrigins = []string{ |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
224 // TODO: Fill me! |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
225 } |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
226 |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
227 func init() { |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
228 cobra.OnInitialize(initConfig) |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
229 fl := RootCmd.PersistentFlags() |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
230 fl.StringVarP(&configFile, "config", "c", "", "config file (default is $HOME/.gemma.toml)") |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
231 |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
232 vbind := func(name string) { viper.BindPFlag(name, fl.Lookup(name)) } |
302
0777aa6de45b
Password reset. Part I
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
221
diff
changeset
|
233 |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
234 str := func(name, value, usage string) { |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
235 fl.String(name, value, usage) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
236 vbind(name) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
237 } |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
238 strP := func(name, shorthand, value, usage string) { |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
239 fl.StringP(name, shorthand, value, usage) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
240 vbind(name) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
241 } |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
242 ui := func(name string, value uint, usage string) { |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
243 fl.Uint(name, value, usage) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
244 vbind(name) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
245 } |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
246 uiP := func(name, shorthand string, value uint, usage string) { |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
247 fl.UintP(name, shorthand, value, usage) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
248 vbind(name) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
249 } |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
250 strSl := func(name string, value []string, usage string) { |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
251 fl.StringSlice(name, value, usage) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
252 vbind(name) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
253 } |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
254 bl := func(name string, value bool, usage string) { |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
255 fl.Bool(name, value, usage) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
256 vbind(name) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
257 } |
3161
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3104
diff
changeset
|
258 d := func(name string, value time.Duration, usage string) { |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3104
diff
changeset
|
259 fl.Duration(name, value, usage) |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3104
diff
changeset
|
260 vbind(name) |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3104
diff
changeset
|
261 } |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
262 |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
263 strP("db-host", "H", "localhost", "host of the database") |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
264 uiP("db-port", "P", 5432, "port of the database") |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
265 strP("db-name", "d", "gemma", "name of the database") |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
266 str("db-user", "meta_login", "Metamorphic database user") |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
267 str("db-password", "", "Metamorphic database user password") |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
268 strP("db-ssl", "S", "prefer", "SSL mode of the database") |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
269 |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
270 strP("sessions", "s", "", "path to the sessions file") |
3162
659549608644
Config: Fixed type of session timeout (its a duration now ... as intended).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3161
diff
changeset
|
271 d("session-timeout", 3*time.Hour, "duration until sessions expire") |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
272 |
394
f24ed1d570c7
server: add default value for serving "web".
Bernhard Reiter <bernhard@intevation.de>
parents:
386
diff
changeset
|
273 strP("web", "w", "./web", "path to the web files") |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
274 strP("host", "o", "localhost", "host of the web app") |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
275 uiP("port", "p", 8000, "port of the web app") |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
276 |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
277 str("mail-host", "localhost", "server to send mail with") |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
278 ui("mail-port", 465, "port of server to send mail with") |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
279 str("mail-user", "gemma", "user to authenticate against mail-host.\n"+ |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
280 "Leave empty for trying to send without auth.") |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
281 str("mail-password", "", "password of user to send mail with") |
489
8f3f7577fbe7
proxy: fix minor typo in default for --mail-from
Bernhard Reiter <bernhard@intevation.de>
parents:
449
diff
changeset
|
282 str("mail-from", "noreply@localhost", "from line of mails") |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
283 str("mail-helo", "localhost", "name of server to send mail from.") |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
284 |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
285 strSl("allowed-origins", allowedOrigins, "allow access for remote origins") |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
286 |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
287 str("geoserver-url", "http://localhost:8080/geoserver", "URL to GeoServer") |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
288 str("geoserver-user", "admin", "GeoServer user") |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
289 str("geoserver-password", "geoserver", "GeoServer password") |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
290 bl("geoserver-clean", false, "Clean GeoServer setup") |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
291 |
1644
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
292 str("proxy-key", "", "signing key for proxy URLs.\n"+ |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
293 "Defaults to random key.") |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
294 str("proxy-prefix", "", "URL prefix of proxy.\n"+ |
2901
da1d063ee085
improve cmd/gemma/gemma --help
Bernhard Reiter <bernhard@intevation.de>
parents:
2639
diff
changeset
|
295 "Defaults to 'http://${host}:${port}'") |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
296 |
1644
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
297 str("external-url", "", "URL to find the server from the outside.\n"+ |
2901
da1d063ee085
improve cmd/gemma/gemma --help
Bernhard Reiter <bernhard@intevation.de>
parents:
2639
diff
changeset
|
298 "Defaults to 'http://${host}:${port}'") |
1644
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
299 |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
300 str("tmp-dir", "", "Temp directory of gemma server.\n"+ |
eadf84bb0e98
New config variable 'external-url'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1366
diff
changeset
|
301 "Defaults to system temp directory.") |
2181
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1644
diff
changeset
|
302 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1644
diff
changeset
|
303 str("schema-dirs", ".", "Directories to find XSD schema files in (recursive).") |
3104
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2906
diff
changeset
|
304 |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2906
diff
changeset
|
305 str("published-config", "", "path to a config file served to client.") |
3161
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3104
diff
changeset
|
306 |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4624
diff
changeset
|
307 str("report-path", "", "path to a report templates.") |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4624
diff
changeset
|
308 |
3582
317d176ef38c
GM import: Try three times when timeouts happen on SOAP service. Increase SOAP timeout to 3 minutes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3169
diff
changeset
|
309 d("soap-timeout", 3*time.Minute, "Timeout till a SOAP request is canceled.") |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
310 |
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
311 str("log-file", "", "path to a file to log to.") |
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
312 str("log-level", log.InfoLogLevel.String(), "path to a file to log to.") |
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
313 |
5610
a826d84485c8
Use token server to fetch token for ERDMS requests.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
314 str("token-url", "", "URL to the ERDMS token server.") |
1000
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
315 } |
958
2818ad6c7d32
Started with import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
874
diff
changeset
|
316 |
1000
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
317 var ( |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
318 configCond = sync.NewCond(new(sync.Mutex)) |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
319 configReady bool |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
320 ) |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
321 |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
322 // Ready tells if the configuration is ready to use.. |
1000
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
323 func Ready() { |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
324 configCond.L.Lock() |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
325 defer configCond.L.Unlock() |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
326 configReady = true |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
327 configCond.Broadcast() |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
328 } |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
329 |
1366
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
330 // WaitReady blocks until the configuration is ready to use. |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
331 // Call this if you have a go routine that needs configuration |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
332 // support. This guarantees that the initialization is done |
a25a4d4a3e6e
Backend: Added the internal api documentation of the config mechanism of the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1334
diff
changeset
|
333 // before accessing the configuration data. |
1000
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
334 func WaitReady() { |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
335 configCond.L.Lock() |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
336 defer configCond.L.Unlock() |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
337 for !configReady { |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
338 configCond.Wait() |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
339 } |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
340 } |
325
c23eb0f34e39
Added CORS support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
302
diff
changeset
|
341 |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
342 func initConfig() { |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
343 // Don't forget to read config either from cfgFile or from home directory! |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
344 if configFile != "" { |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
345 // Use config file from the flag. |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
346 viper.SetConfigFile(configFile) |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
347 } else { |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
348 // Find home directory. |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
349 home, err := homedir.Dir() |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
350 if err != nil { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
351 lg.Fatalf("error: %v\n", err) |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
352 } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
353 |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
354 // Search config in home directory with name ".cobra" (without extension). |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
355 viper.AddConfigPath(home) |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
356 viper.SetConfigName(".gemma") |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
357 } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
358 if err := viper.ReadInConfig(); err != nil { |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
359 if _, ok := err.(viper.ConfigFileNotFoundError); ok && configFile == "" { |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
360 // Don't bother if not found. |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
361 return |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
362 } |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
363 lg.Fatalf("Can't read config: %v\n", err) |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
364 } |
28
714787accd26
Fetch database connection string parts from configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
365 } |