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

Function StringToIPNetHookFunc

decode_hooks.go:167–183  ·  view source on GitHub ↗

StringToIPNetHookFunc returns a DecodeHookFunc that converts strings to net.IPNet

()

Source from the content-addressed store, hash-verified

165// StringToIPNetHookFunc returns a DecodeHookFunc that converts
166// strings to net.IPNet
167func StringToIPNetHookFunc() DecodeHookFunc {
168 return func(
169 f reflect.Type,
170 t reflect.Type,
171 data interface{}) (interface{}, error) {
172 if f.Kind() != reflect.String {
173 return data, nil
174 }
175 if t != reflect.TypeOf(net.IPNet{}) {
176 return data, nil
177 }
178
179 // Convert it by parsing
180 _, net, err := net.ParseCIDR(data.(string))
181 return net, err
182 }
183}
184
185// StringToTimeHookFunc returns a DecodeHookFunc that converts
186// strings to time.Time.

Callers 1

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…