Skip to content

Commit

Permalink
fix: change receiver type from Plugin to *Plugin
Browse files Browse the repository at this point in the history
Signed-off-by: nscuro <[email protected]>
  • Loading branch information
nscuro committed Oct 28, 2021
1 parent 47e11e1 commit 2c4ca53
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func New(_ context.Context, next http.Handler, cfg *Config, name string) (http.H
}, nil
}

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
Expand All @@ -96,7 +96,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) (ips []string) {
func (p *Plugin) GetRemoteIPs(req *http.Request) (ips []string) {
ipMap := make(map[string]struct{})

if xff := req.Header.Get("x-forwarded-for"); xff != "" {
Expand Down Expand Up @@ -128,7 +128,7 @@ func (p Plugin) GetRemoteIPs(req *http.Request) (ips []string) {
var ErrNotAllowed = errors.New("not allowed")

// CheckAllowed checks whether a given IP address is allowed according to the configured allowed countries.
func (p Plugin) CheckAllowed(ip string) (string, error) {
func (p *Plugin) CheckAllowed(ip string) (string, error) {
country, err := p.Lookup(ip)
if err != nil {
return "", fmt.Errorf("lookup of %s failed: %w", ip, err)
Expand Down Expand Up @@ -156,7 +156,7 @@ func (p Plugin) CheckAllowed(ip string) (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
Expand Down

0 comments on commit 2c4ca53

Please sign in to comment.