MCPcopy
hub / github.com/mitchellh/mapstructure / StringToIPHookFunc

Function StringToIPHookFunc

decode_hooks.go:143–163  ·  view source on GitHub ↗

StringToIPHookFunc returns a DecodeHookFunc that converts strings to net.IP

()

Source from the content-addressed store, hash-verified

141// StringToIPHookFunc returns a DecodeHookFunc that converts
142// strings to net.IP
143func StringToIPHookFunc() DecodeHookFunc {
144 return func(
145 f reflect.Type,
146 t reflect.Type,
147 data interface{}) (interface{}, error) {
148 if f.Kind() != reflect.String {
149 return data, nil
150 }
151 if t != reflect.TypeOf(net.IP{}) {
152 return data, nil
153 }
154
155 // Convert it by parsing
156 ip := net.ParseIP(data.(string))
157 if ip == nil {
158 return net.IP{}, fmt.Errorf("failed parsing ip %v", data)
159 }
160
161 return ip, nil
162 }
163}
164
165// StringToIPNetHookFunc returns a DecodeHookFunc that converts
166// strings to net.IPNet

Callers 1

TestStringToIPHookFuncFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestStringToIPHookFuncFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…