NewSourceIPs creates a new SourceIPs
(header, regex string, extractAllHosts bool)
| 46 | |
| 47 | // NewSourceIPs creates a new SourceIPs |
| 48 | func NewSourceIPs(header, regex string, extractAllHosts bool) (*SourceIPExtractor, error) { |
| 49 | if (header == "" && regex != "") || (header != "" && regex == "") { |
| 50 | return nil, fmt.Errorf("either both a header field and a regex have to be given or neither") |
| 51 | } |
| 52 | re, err := regexp.Compile(regex) |
| 53 | if err != nil { |
| 54 | return nil, fmt.Errorf("invalid regex given") |
| 55 | } |
| 56 | |
| 57 | return &SourceIPExtractor{ |
| 58 | header: header, |
| 59 | regex: re, |
| 60 | extractAllHosts: extractAllHosts, |
| 61 | }, nil |
| 62 | } |
| 63 | |
| 64 | // extractHost returns the Host IP address without any port information |
| 65 | func extractHost(address string) string { |