-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
73 lines (56 loc) · 1.2 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
package main
import "path"
type ServerConfig struct {
Headers map[string]string `json:"headers"`
ETag *bool `json:"etag"`
LastMod *bool `json:"lastmod"`
Routes map[string]RouteConfig `json:"routes"`
MimeTypes map[string]string `json:"mimetypes"`
}
type RouteConfig struct {
Headers map[string]string `json:"headers"`
ETag *bool `json:"etag"`
LastMod *bool `json:"lastmod"`
Serve string `json:"serve"`
}
var yes = true
var no = false
var defaultConfig = RouteConfig{ETag: &yes, LastMod: &no}
func NewRouteConfig(sc *ServerConfig, rc *RouteConfig) RouteConfig {
nc := defaultConfig
nc.Headers = make(map[string]string)
if sc == nil {
return nc
}
for k, v := range sc.Headers {
if v != "" {
nc.Headers[k] = v
}
}
if sc.ETag != nil {
nc.ETag = sc.ETag
}
if sc.LastMod != nil {
nc.LastMod = sc.LastMod
}
if rc == nil {
return nc
}
for k, v := range rc.Headers {
if v == "" {
delete(nc.Headers, k)
} else {
nc.Headers[k] = v
}
}
if rc.ETag != nil {
nc.ETag = rc.ETag
}
if rc.LastMod != nil {
nc.LastMod = rc.LastMod
}
if rc.Serve != "" {
nc.Serve = path.Clean("/" + rc.Serve)
}
return nc
}