blob: c64d98d713a1672500c07fee3cde703f9b2985d8 (
plain) (
blame)
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
|
package main
import (
"fmt"
"net"
"strings"
)
type (
ipList []net.IP
stringList []string
)
// return list of IPs as comma separated list
func (il *ipList) String() string {
var res string
list := ([]net.IP)(*il)
for i := range list {
if i > 0 {
res += ", "
}
res += list[i].String()
}
return res
}
// receive multiple ip lists as comma separated strings
func (il *ipList) Set(value string) error {
if len(value) == 0 {
return nil
}
var ip net.IP
parts := strings.Split(value, ",")
for i := range parts {
ip = net.ParseIP(strings.Trim(parts[i], " \t"))
if ip == nil {
// TODO encapsulate error in meaningfull error
return fmt.Errorf("not a valid IP")
}
*il = append(*il, ip)
}
return nil
}
// return string list as a comma separated list
func (al *stringList) String() string {
return strings.Join(([]string)(*al), ", ")
}
// receive multiple string lists as comma separated strings
func (al *stringList) Set(value string) error {
if len(value) == 0 {
return nil
}
parts := strings.Split(value, ",")
for i := range parts {
*al = append(*al, strings.Trim(parts[i], " \t"))
}
return nil
}
|