-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
68 lines (55 loc) · 1.86 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
package changes
import (
"encoding/json"
"os"
"time"
"github.com/omniscale/imposm3/config"
"github.com/pkg/errors"
)
type Config struct {
Connection string `json:"connection"`
Schemas Schemas `json:"schemas"`
LimitTo *LimitTo `json:"changes_bbox"`
DiffDir string `json:"diffdir"`
ChangesDir string `json:"changesdir"`
DiffFromDiffDir bool `json:"replication_from_diffdir"`
DiffUrl string `json:"replication_url"`
DiffInterval config.MinutesInterval `json:"replication_interval"`
ChangesetUrl string `json:"changeset_url"`
ChangesetInterval config.MinutesInterval `json:"changeset_interval"`
ChangesetFromChangesDir bool `json:"changeset_from_changesdir"`
InitialHistory config.MinutesInterval `json:"initial_history"`
}
type Schemas struct {
Changes string `json:"changes"`
}
var DefaultConfig = Config{
InitialHistory: config.MinutesInterval{Duration: 2 * time.Hour},
DiffUrl: "https://planet.openstreetmap.org/replication/minute/",
DiffInterval: config.MinutesInterval{Duration: time.Minute},
ChangesetUrl: "https://planet.openstreetmap.org/replication/changesets/",
ChangesetInterval: config.MinutesInterval{Duration: time.Minute},
Schemas: Schemas{Changes: "changes"},
}
func LoadConfig(filename string) (*Config, error) {
conf := Config(DefaultConfig)
f, err := os.Open(filename)
if err != nil {
return nil, err
}
decoder := json.NewDecoder(f)
err = decoder.Decode(&conf)
if err != nil {
return nil, err
}
if conf.Connection == "" {
return nil, errors.New("missing connection option")
}
if conf.DiffDir == "" {
return nil, errors.New("missing diffdir option")
}
if conf.ChangesDir == "" {
return nil, errors.New("missing changesdir option")
}
return &conf, nil
}