some fixes
This commit is contained in:
parent
9e68b46346
commit
fa65b381a4
7 changed files with 37 additions and 26 deletions
10
pkg/api/types/clientip.go
Normal file
10
pkg/api/types/clientip.go
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// Copyright (C) 2023 Marius Schellenberger
|
||||
|
||||
//go:build !openbsd
|
||||
// +build !openbsd
|
||||
|
||||
package types
|
||||
|
||||
func clientip(ip string) string {
|
||||
return ip
|
||||
}
|
||||
13
pkg/api/types/clientip_openbsd.go
Normal file
13
pkg/api/types/clientip_openbsd.go
Normal 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
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue