1
0
Fork 0

Update linter

This commit is contained in:
Ludovic Fernandez 2020-05-11 12:06:07 +02:00 committed by GitHub
parent f12c27aa7c
commit 328611c619
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
157 changed files with 489 additions and 508 deletions

View file

@ -10,15 +10,15 @@ const (
xForwardedFor = "X-Forwarded-For"
)
// Strategy a strategy for IP selection
// Strategy a strategy for IP selection.
type Strategy interface {
GetIP(req *http.Request) string
}
// RemoteAddrStrategy a strategy that always return the remote address
// RemoteAddrStrategy a strategy that always return the remote address.
type RemoteAddrStrategy struct{}
// GetIP returns the selected IP
// GetIP returns the selected IP.
func (s *RemoteAddrStrategy) GetIP(req *http.Request) string {
ip, _, err := net.SplitHostPort(req.RemoteAddr)
if err != nil {
@ -27,12 +27,12 @@ func (s *RemoteAddrStrategy) GetIP(req *http.Request) string {
return ip
}
// DepthStrategy a strategy based on the depth inside the X-Forwarded-For from right to left
// DepthStrategy a strategy based on the depth inside the X-Forwarded-For from right to left.
type DepthStrategy struct {
Depth int
}
// GetIP return the selected IP
// GetIP return the selected IP.
func (s *DepthStrategy) GetIP(req *http.Request) string {
xff := req.Header.Get(xForwardedFor)
xffs := strings.Split(xff, ",")
@ -44,12 +44,12 @@ func (s *DepthStrategy) GetIP(req *http.Request) string {
}
// CheckerStrategy a strategy based on an IP Checker
// allows to check that addresses are in a trusted IPs
// allows to check that addresses are in a trusted IPs.
type CheckerStrategy struct {
Checker *Checker
}
// GetIP return the selected IP
// GetIP return the selected IP.
func (s *CheckerStrategy) GetIP(req *http.Request) string {
if s.Checker == nil {
return ""