From dd044588869dd6043c9cbd5cefd1220aa6760584 Mon Sep 17 00:00:00 2001 From: nscuro Date: Sun, 3 Apr 2022 20:01:34 +0200 Subject: [PATCH] fix: change plugin receiver from value to pointer Signed-off-by: nscuro --- plugin.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin.go b/plugin.go index 3feb09d..790b277 100644 --- a/plugin.go +++ b/plugin.go @@ -82,7 +82,7 @@ func New(_ context.Context, next http.Handler, cfg *Config, name string) (http.H } // ServeHTTP implements the http.Handler interface. -func (p Plugin) ServeHTTP(rw http.ResponseWriter, req *http.Request) { +func (p *Plugin) ServeHTTP(rw http.ResponseWriter, req *http.Request) { if !p.enabled { p.next.ServeHTTP(rw, req) return @@ -108,7 +108,7 @@ func (p Plugin) ServeHTTP(rw http.ResponseWriter, req *http.Request) { } // GetRemoteIPs collects the remote IPs from the X-Forwarded-For and X-Real-IP headers. -func (p Plugin) GetRemoteIPs(req *http.Request) []string { +func (p *Plugin) GetRemoteIPs(req *http.Request) []string { uniqIPs := make(map[string]struct{}) if xff := req.Header.Get("x-forwarded-for"); xff != "" { @@ -158,7 +158,7 @@ func (e NotAllowedError) Error() (err string) { } // CheckAllowed checks whether a given IP address is allowed according to the configured allowed countries. -func (p Plugin) CheckAllowed(ip string) error { +func (p *Plugin) CheckAllowed(ip string) error { country, err := p.Lookup(ip) if err != nil { return fmt.Errorf("lookup of %s failed: %w", ip, err) @@ -193,7 +193,7 @@ func (p Plugin) CheckAllowed(ip string) error { } // Lookup queries the ip2location database for a given IP address. -func (p Plugin) Lookup(ip string) (string, error) { +func (p *Plugin) Lookup(ip string) (string, error) { record, err := p.db.Get_country_short(ip) if err != nil { return "", err