forked from StationA/tilenol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
83 lines (73 loc) · 1.96 KB
/
config.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 tilenol
import (
"os"
"gopkg.in/yaml.v3"
)
// Config is a YAML server configuration object
type Config struct {
// Cache configures the tile server cache
Cache *CacheConfig `yaml:"cache"`
// Layers configures the tile server layers
Layers []LayerConfig `yaml:"layers"`
}
// LoadConfig loads the configuration from disk, and decodes it into a Config object
func LoadConfig(configFile *os.File) (*Config, error) {
dec := yaml.NewDecoder(configFile)
var config Config
err := dec.Decode(&config)
if err != nil {
return nil, err
}
Logger.Debugf("Loaded config: %+v", config)
return &config, nil
}
// ConfigOption is a function that changes a configuration setting of the server.Server
type ConfigOption func(s *Server) error
// ConfigFile loads a YAML configuration file from disk to set up the server
func ConfigFile(configFile *os.File) ConfigOption {
return func(s *Server) error {
config, err := LoadConfig(configFile)
if err != nil {
return err
}
cache, err := CreateCache(config.Cache)
if err != nil {
return err
}
s.Cache = cache
var layers []Layer
for _, layerConfig := range config.Layers {
layer, err := CreateLayer(layerConfig)
if err != nil {
return err
}
layers = append(layers, *layer)
}
s.Layers = layers
return nil
}
}
// Port changes the port number used for serving tile data
func Port(port uint16) ConfigOption {
return func(s *Server) error {
s.Port = port
return nil
}
}
// InternalPort changes the port number used for administrative endpoints (e.g. healthcheck)
func InternalPort(internalPort uint16) ConfigOption {
return func(s *Server) error {
s.InternalPort = internalPort
return nil
}
}
// EnableCORS configures the server for CORS (cross-origin resource sharing)
func EnableCORS(s *Server) error {
s.EnableCORS = true
return nil
}
// SimplifyShapes enables geometry simplification based on the requested zoom level
func SimplifyShapes(s *Server) error {
s.Simplify = true
return nil
}