use fallback if not x-forwarded-for is present
This commit is contained in:
3
main.go
3
main.go
@@ -1105,10 +1105,9 @@ func main() {
|
||||
go housekeeping()
|
||||
|
||||
r := gin.New()
|
||||
|
||||
r.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
|
||||
return fmt.Sprintf("%s - \"%s %s %s %d %s \"%s\" %s\"\n",
|
||||
param.Request.Header.Get("X-Forwarded-For"),
|
||||
utils.RealIP(¶m.Request.Header, param.Request.RemoteAddr),
|
||||
param.Method,
|
||||
param.Path,
|
||||
param.Request.Proto,
|
||||
|
@@ -815,3 +815,11 @@ func PlayerFromSteam(players []*ent.Player, db *ent.Client, apiKey string, rl *r
|
||||
|
||||
return nPlayers, nil
|
||||
}
|
||||
|
||||
func RealIP(header *http.Header, fallback string) string {
|
||||
if header.Get("X-Forwarded-For") != "" {
|
||||
return header.Get("X-Forwarded-For")
|
||||
} else {
|
||||
return fallback
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user