-
Notifications
You must be signed in to change notification settings - Fork 56
/
params.go
54 lines (43 loc) · 1.08 KB
/
params.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
package goVirtualHost
import "fmt"
func (params params) validateParam(param *param) (errs []error) {
proto := param.proto
addr := param.addr
hostnames := param.hostNames
for _, ownParam := range params {
if ownParam == param {
continue
}
if ownParam.proto != proto || ownParam.addr != addr {
continue
}
ownUseTLS := ownParam.cert != nil
inputUseTLS := param.cert != nil
if ownUseTLS != inputUseTLS {
err := fmt.Errorf("cannot serve for both Plain and TLS mode: %+v", param)
errs = append(errs, err)
}
if (len(hostnames) == 0 && len(ownParam.hostNames) == 0) || (ownParam.hasHostNames(hostnames)) {
err := fmt.Errorf("duplicated address and hostname: %+v", param)
errs = append(errs, err)
}
}
return
}
func (params params) validate(inputs params) (errs []error) {
for _, p := range inputs {
es := p.validate()
if len(es) > 0 {
errs = append(errs, es...)
}
es = params.validateParam(p)
if len(es) > 0 {
errs = append(errs, es...)
}
es = inputs.validateParam(p)
if len(es) > 0 {
errs = append(errs, es...)
}
}
return
}