-
Notifications
You must be signed in to change notification settings - Fork 10
/
net.go
33 lines (28 loc) · 657 Bytes
/
net.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
package flagsfiller
import (
"fmt"
"net"
"reflect"
)
func init() {
RegisterSimpleType(ipConverter)
RegisterSimpleType(ipnetConverter)
RegisterSimpleType(macConverter)
}
func ipConverter(s string, tag reflect.StructTag) (net.IP, error) {
addr := net.ParseIP(s)
if addr == nil {
return nil, fmt.Errorf("%s is not a valid IP address", s)
}
return addr, nil
}
func ipnetConverter(s string, tag reflect.StructTag) (net.IPNet, error) {
_, prefix, err := net.ParseCIDR(s)
if err != nil {
return net.IPNet{}, err
}
return *prefix, nil
}
func macConverter(s string, tag reflect.StructTag) (net.HardwareAddr, error) {
return net.ParseMAC(s)
}