parseIPCIDR parses an IP address string with CIDR notation.
(ipCIDR string, ipType string)
| 260 | |
| 261 | // parseIPCIDR parses an IP address string with CIDR notation. |
| 262 | func parseIPCIDR(ipCIDR string, ipType string) (IPAddress, bool) { |
| 263 | if ipCIDR == "" { |
| 264 | return IPAddress{}, false |
| 265 | } |
| 266 | |
| 267 | parts := strings.Split(ipCIDR, "/") |
| 268 | if len(parts) == 0 { |
| 269 | return IPAddress{}, false |
| 270 | } |
| 271 | |
| 272 | ipAddr := IPAddress{Type: ipType} |
| 273 | ipAddr.Address = parts[0] |
| 274 | |
| 275 | if len(parts) == 2 { |
| 276 | prefix, err := parseInt(parts[1]) // Assuming you have a helper like strconv.Atoi or similar |
| 277 | if err == nil { |
| 278 | ipAddr.Prefix = prefix |
| 279 | } |
| 280 | // Could log an error here if prefix parsing fails but IP is present |
| 281 | // For now, we still consider it a valid IP, just without a prefix |
| 282 | } |
| 283 | |
| 284 | return ipAddr, true |
| 285 | } |
| 286 | |
| 287 | // Helper function to parse int, assuming it might be missing in this context |
| 288 | // For a real scenario, use strconv.Atoi. |
no test coverage detected