-
Notifications
You must be signed in to change notification settings - Fork 1
/
verify.go
77 lines (60 loc) · 1.6 KB
/
verify.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
package config
import (
"errors"
"fmt"
"net"
"net/url"
"os"
"os/user"
"path"
)
// Checks all fields in the parsed configs for wrong values. If found, returns error
// explaining the problem.
func (cfg *Config) Verify() error {
if cfg.System.User != "" {
if _, err := user.Lookup(cfg.System.User); err != nil {
return fmt.Errorf("Wrong system.user directive. %s", err)
}
}
if cfg.HTTP.Listen == "" {
return errors.New("Empty listen directive")
}
//!TODO: make sure Listen is valid tcp address
if _, err := net.ResolveTCPAddr("tcp", cfg.HTTP.Listen); err != nil {
return err
}
if cfg.System.Pidfile == "" {
return errors.New("Empty pidfile")
}
pidDir := path.Dir(cfg.System.Pidfile)
st, err := os.Stat(pidDir)
if err != nil {
return fmt.Errorf("Pidfile directory: %s", err)
}
if !st.IsDir() {
return fmt.Errorf("%s is not a directory", pidDir)
}
cacheZonesMap := make(map[uint32]*CacheZoneSection)
for _, cz := range cfg.CacheZones {
cacheZonesMap[cz.ID] = cz
}
for _, virtualHost := range cfg.HTTP.Servers {
parsed, err := url.Parse(virtualHost.UpstreamAddress)
if err != nil {
return fmt.Errorf("Error parsing server %s upstream. %s",
virtualHost.Name, err)
}
if !parsed.IsAbs() {
return fmt.Errorf("Upstream address was not absolute: %s",
virtualHost.UpstreamAddress)
}
virtualHost.upstreamAddressUrl = parsed
if cz, ok := cacheZonesMap[virtualHost.CacheZone]; ok {
virtualHost.cacheZone = cz
} else {
return fmt.Errorf("Upstream %s has not existing cache zone id. %d",
virtualHost.Name, virtualHost.CacheZone)
}
}
return nil
}