some fixes

This commit is contained in:
ston1th 2023-03-23 00:08:33 +01:00
commit fa65b381a4
7 changed files with 37 additions and 26 deletions

10
pkg/api/types/clientip.go Normal file
View file

@ -0,0 +1,10 @@
// Copyright (C) 2023 Marius Schellenberger
//go:build !openbsd
// +build !openbsd
package types
func clientip(ip string) string {
return ip
}

View file

@ -0,0 +1,13 @@
// Copyright (C) 2023 Marius Schellenberger
//go:build openbsd
// +build openbsd
package types
func clientip(ip string) string {
if ip == "" {
return "@"
}
return ip
}

View file

@ -5,7 +5,6 @@ package types
import (
"encoding/json"
"io"
"net"
"net/http"
"github.com/go-logr/logr"
@ -28,6 +27,7 @@ func NewContext(w http.ResponseWriter, r *http.Request, data *ContextData, log l
Response: w,
Data: data,
Log: log,
ip: clientip(r.RemoteAddr),
}
}
@ -70,17 +70,8 @@ func (c *Context) Form(name string) string {
return c.Request.FormValue(name)
}
func (c *Context) ClientIP() (host string) {
host = c.Request.RemoteAddr
if host == "@" {
return
}
if c.ip != "" {
return c.ip
}
host, _, _ = net.SplitHostPort(host)
c.ip = host
return
func (c *Context) ClientIP() string {
return c.ip
}
// Var returns the given url variable