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

35 lines
571 B
Go
Raw Normal View History

2019-01-18 11:03:57 +03:00
package app
import (
2019-01-18 11:13:37 +03:00
"encoding/json"
"io/ioutil"
"os"
2019-01-18 11:03:57 +03:00
)
type Config struct {
2019-01-18 11:13:37 +03:00
Port int `json:"port"`
EnableInitialRendering bool `json:"enableinitialrendering"`
2019-01-18 11:03:57 +03:00
}
func ParseConfig(filename string) (*Config, error) {
2019-01-18 11:13:37 +03:00
cfg := Config{
Port: 80,
EnableInitialRendering: true,
}
2019-01-18 11:03:57 +03:00
2019-01-18 11:13:37 +03: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 11:03:57 +03:00
2019-01-18 11:13:37 +03:00
err = json.Unmarshal(data, &cfg)
if err != nil {
return nil, err
}
}
2019-01-18 11:03:57 +03:00
2019-01-18 11:13:37 +03:00
return &cfg, nil
2019-01-18 11:03:57 +03:00
}