StringToIPHookFunc returns a DecodeHookFunc that converts strings to net.IP
()
| 141 | // StringToIPHookFunc returns a DecodeHookFunc that converts |
| 142 | // strings to net.IP |
| 143 | func 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 |
no outgoing calls
searching dependent graphs…