Contains checks whether passed addr is in the range of networks
(addr string)
| 112 | |
| 113 | // Contains checks whether passed addr is in the range of networks |
| 114 | func (n Networks) Contains(addr string) bool { |
| 115 | if len(n) == 0 { |
| 116 | return true |
| 117 | } |
| 118 | |
| 119 | h, _, err := net.SplitHostPort(addr) |
| 120 | if err != nil { |
| 121 | // If we only have an IP address. This happens when the proxy middleware is enabled. |
| 122 | h = addr |
| 123 | } |
| 124 | |
| 125 | ip := net.ParseIP(h) |
| 126 | if ip == nil { |
| 127 | panic(fmt.Sprintf("BUG: unexpected error while parsing IP: %s", h)) |
| 128 | } |
| 129 | |
| 130 | for _, ipnet := range n { |
| 131 | if ipnet.Contains(ip) { |
| 132 | return true |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return false |
| 137 | } |
| 138 | |
| 139 | // Duration wraps time.Duration. It is used to parse the custom duration format |
| 140 | type Duration time.Duration |
no outgoing calls