-
Notifications
You must be signed in to change notification settings - Fork 280
/
validate.go
59 lines (49 loc) · 1.61 KB
/
validate.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
package config
import (
"fmt"
"net"
"strconv"
"strings"
envoy_config_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
)
// DNSLookupFamily values.
const (
DNSLookupFamilyAuto = "AUTO"
DNSLookupFamilyV4Only = "V4_ONLY"
DNSLookupFamilyV6Only = "V6_ONLY"
)
// AllDNSLookupFamilies are all the available DNSLookupFamily values.
var AllDNSLookupFamilies = []string{DNSLookupFamilyV6Only, DNSLookupFamilyV4Only, DNSLookupFamilyAuto}
// ValidateDNSLookupFamily validates the value to confirm its one of the available DNS lookup families.
func ValidateDNSLookupFamily(value string) error {
switch value {
case "", DNSLookupFamilyAuto, DNSLookupFamilyV4Only, DNSLookupFamilyV6Only:
return nil
}
return fmt.Errorf("unknown dns_lookup_family: %s, known families are: %s", value, strings.Join(AllDNSLookupFamilies, ", "))
}
// GetEnvoyDNSLookupFamily gets the envoy DNS lookup family.
func GetEnvoyDNSLookupFamily(value string) envoy_config_cluster_v3.Cluster_DnsLookupFamily {
switch value {
case DNSLookupFamilyV4Only:
return envoy_config_cluster_v3.Cluster_V4_ONLY
case DNSLookupFamilyV6Only:
return envoy_config_cluster_v3.Cluster_V6_ONLY
}
return envoy_config_cluster_v3.Cluster_AUTO
}
// ValidateMetricsAddress validates address for the metrics
func ValidateMetricsAddress(addr string) error {
_, port, err := net.SplitHostPort(addr)
if err != nil || port == "" {
return fmt.Errorf("expected host:port")
}
p, err := strconv.Atoi(port)
if err != nil {
return fmt.Errorf("port must be a number")
}
if p <= 0 {
return fmt.Errorf("expected positive port number")
}
return nil
}