1
0
forked from MTSR/mapserver
mapserver/app/config.go

49 lines
1003 B
Go
Raw Normal View History

2019-01-18 09:03:57 +01:00
package app
import (
2019-01-18 09:13:37 +01:00
"encoding/json"
"io/ioutil"
"os"
2019-01-18 09:03:57 +01:00
)
type Config struct {
2019-01-18 13:50:59 +01:00
Port int `json:"port"`
EnableInitialRendering bool `json:"enableinitialrendering"`
EnableIncrementalUpdate bool `json:"enableincrementalupdate"`
Webdev bool `json:"webdev"`
WebApi WebApiConfig `json:"webapi"`
2019-01-18 11:04:37 +01:00
}
type WebApiConfig struct {
EnableMapblock bool `json:"enablemapblock"`
2019-01-18 09:03:57 +01:00
}
func ParseConfig(filename string) (*Config, error) {
2019-01-18 11:04:37 +01:00
webapi := WebApiConfig{
EnableMapblock: false,
}
2019-01-18 09:13:37 +01:00
cfg := Config{
2019-01-18 13:50:59 +01:00
Port: 8080,
EnableInitialRendering: true,
2019-01-18 13:07:01 +01:00
EnableIncrementalUpdate: true,
2019-01-18 13:50:59 +01:00
Webdev: false,
WebApi: webapi,
2019-01-18 09:13:37 +01:00
}
2019-01-18 09:03:57 +01:00
2019-01-18 09:13:37 +01:00
info, err := os.Stat(filename)
if info != nil && err == nil {
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
2019-01-18 09:03:57 +01:00
2019-01-18 09:13:37 +01:00
err = json.Unmarshal(data, &cfg)
if err != nil {
return nil, err
}
}
2019-01-18 09:03:57 +01:00
2019-01-18 09:13:37 +01:00
return &cfg, nil
2019-01-18 09:03:57 +01:00
}