forked from MTSR/mapserver
feat: added configuration options via Environment (#333)
This commit is contained in:
parent
2114ee5c32
commit
69b963ed6e
@ -1,4 +1,7 @@
|
||||
FROM scratch
|
||||
COPY mapserver /bin/mapserver
|
||||
ENV MT_CONFIG_PATH "/bin/mapserver.json"
|
||||
ENV MT_LOGLEVEL "INFO"
|
||||
ENV MT_READONLY "false"
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["/bin/mapserver"]
|
||||
ENTRYPOINT ["/bin/mapserver"]
|
23
main.go
23
main.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"mapserver/app"
|
||||
"mapserver/mapobject"
|
||||
"mapserver/params"
|
||||
@ -13,11 +14,19 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
//Parse command line
|
||||
//get Env or Default value
|
||||
env := func(key string, defaultVal string) string {
|
||||
val, ok := os.LookupEnv(key)
|
||||
if !ok {
|
||||
return defaultVal
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
//Parse command line
|
||||
p := params.Parse()
|
||||
|
||||
if p.Debug {
|
||||
if p.Debug || env("MT_LOGLEVEL", "INFO") == "DEBUG" {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
} else {
|
||||
logrus.SetLevel(logrus.InfoLevel)
|
||||
@ -39,15 +48,17 @@ func main() {
|
||||
}
|
||||
|
||||
//parse Config
|
||||
cfg, err := app.ParseConfig(app.ConfigFile)
|
||||
cfg, err := app.ParseConfig(env("MT_CONFIG_PATH", app.ConfigFile))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
//write back config with all values
|
||||
err = cfg.Save()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if env("MT_READONLY", "false") != "true" {
|
||||
err = cfg.Save()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
//exit after creating the config
|
||||
|
Loading…
Reference in New Issue
Block a user