MCPcopy
hub / github.com/grafana/dskit / NewSourceIPs

Function NewSourceIPs

middleware/source_ips.go:48–62  ·  view source on GitHub ↗

NewSourceIPs creates a new SourceIPs

(header, regex string, extractAllHosts bool)

Source from the content-addressed store, hash-verified

46
47// NewSourceIPs creates a new SourceIPs
48func 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
65func extractHost(address string) string {

Callers 6

BuildHTTPMiddlewareFunction · 0.92
TestGetSourceIPsFunction · 0.85
TestInvalidFunction · 0.85

Calls 1

ErrorfMethod · 0.80

Tested by 5

TestGetSourceIPsFunction · 0.68
TestInvalidFunction · 0.68