-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.go
83 lines (68 loc) · 1.32 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"fmt"
"os"
"mapserver/app"
"mapserver/mapobject"
"mapserver/params"
"mapserver/tilerendererjob"
"mapserver/web"
"runtime"
"github.com/sirupsen/logrus"
)
func main() {
//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 || env("MT_LOGLEVEL", "INFO") == "DEBUG" {
logrus.SetLevel(logrus.DebugLevel)
} else {
logrus.SetLevel(logrus.InfoLevel)
}
if p.Help {
params.PrintHelp()
return
}
if p.Version {
fmt.Print("Mapserver version: ")
fmt.Println(app.Version)
fmt.Print("OS: ")
fmt.Println(runtime.GOOS)
fmt.Print("Architecture: ")
fmt.Println(runtime.GOARCH)
return
}
//parse Config
cfg, err := app.ParseConfig(env("MT_CONFIG_PATH", app.ConfigFile))
if err != nil {
panic(err)
}
//write back config with all values
if env("MT_READONLY", "false") != "true" {
err = cfg.Save()
if err != nil {
panic(err)
}
}
//exit after creating the config
if p.CreateConfig {
return
}
//setup app context
ctx := app.Setup(p, cfg)
//Set up mapobject events
mapobject.Setup(ctx)
//run initial rendering
if ctx.Config.EnableRendering {
go tilerendererjob.Job(ctx)
}
//Start http server
web.Serve(ctx)
}