/
config.go
96 lines (76 loc) · 2.17 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
84
85
86
87
88
89
90
91
92
93
94
95
96
package config
import (
"encoding/json"
"io/ioutil"
)
type Config struct {
Level LevelConfig `json:"level"`
Graphics GraphicsConfig `json:"graphics"`
Features FeaturesConfig `json:"features"`
Images ImagesConfig `json:"images"`
Derivatives DerivativesConfig `json:"derivatives"`
Flickr FlickrConfig `json:"flickr,omitempty"`
Primitive PrimitiveConfig `json:"primitive,omitempty"`
}
type LevelConfig struct {
Compliance string `json:"compliance"`
}
type FeaturesConfig struct {
Enable FeaturesToggle `json:"enable"`
Disable FeaturesToggle `json:"disable"`
Append FeaturesAppend `json:"append"`
}
type FeaturesToggle map[string][]string
type FeaturesAppend map[string]map[string]FeaturesDetails
type FeaturesDetails struct {
Syntax string `json:"syntax"`
Required bool `json:"required"`
Supported bool `json:"supported"`
Match string `json:"match,omitempty"`
}
type ImagesConfig struct {
Source SourceConfig `json:"source"`
Cache CacheConfig `json:"cache"`
}
type DerivativesConfig struct {
Cache CacheConfig `json:"cache"`
}
type GraphicsConfig struct {
Source SourceConfig `json:"source"`
}
type SourceConfig struct {
Name string `json:"name"`
Path string `json:"path,omitempty"`
Prefix string `json:"prefix,omitempty"`
Region string `json:"region,omitempty"`
Credentials string `json:"credentials,omitempty"`
Tmpdir string `json:"tmpdir,omitempty"`
}
type FlickrConfig struct {
ApiKey string `json:"apikey"`
ApiSecret string `json:"apisecret,omitempty"`
}
type PrimitiveConfig struct {
MaxIterations int `json:"max_iterations"`
}
type CacheConfig struct {
Name string `json:"name"`
Path string `json:"path,omitempty"`
TTL int `json:"ttl,omitempty"`
Limit int `json:"limit,omitempty"`
Prefix string `json:"prefix,omitempty"`
Region string `json:"region,omitempty"`
Credentials string `json:"credentials,omitempty"`
}
func NewConfigFromFile(file string) (*Config, error) {
body, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
c := Config{}
err = json.Unmarshal(body, &c)
if err != nil {
return nil, err
}
return &c, nil
}