mapserver/app/config.go
2019-01-18 11:04:37 +01:00

47 lines
891 B
Go

package app
import (
"encoding/json"
"io/ioutil"
"os"
)
type Config struct {
Port int `json:"port"`
EnableInitialRendering bool `json:"enableinitialrendering"`
Webdev bool `json:"webdev"`
WebApi WebApiConfig `json:"webapi"`
}
type WebApiConfig struct {
EnableMapblock bool `json:"enablemapblock"`
}
func ParseConfig(filename string) (*Config, error) {
webapi := WebApiConfig{
EnableMapblock: false,
}
cfg := Config{
Port: 8080,
EnableInitialRendering: true,
Webdev: false,
WebApi: webapi,
}
info, err := os.Stat(filename)
if info != nil && err == nil {
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
err = json.Unmarshal(data, &cfg)
if err != nil {
return nil, err
}
}
return &cfg, nil
}