mapserver/app/config.go

35 lines
576 B
Go
Raw Normal View History

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