feat: 统一sql命名、函数命名
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"server/internal/config"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"server/internal/pkg/errs"
|
||||
"server/internal/pkg/validator"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
@@ -71,6 +73,28 @@ func BindJson(r *http.Request, dest any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClientIP 获取客户端 IP,依次从 X-Forwarded-For、X-Real-IP、RemoteAddr 取值
|
||||
func ClientIP(r *http.Request) string {
|
||||
if xff := r.Header.Get("X-Forwarded-For"); xff != "" {
|
||||
parts := strings.Split(xff, ",")
|
||||
if len(parts) > 0 {
|
||||
return strings.TrimSpace(parts[0])
|
||||
}
|
||||
}
|
||||
|
||||
if ip := r.Header.Get("X-Real-IP"); ip != "" {
|
||||
return ip
|
||||
}
|
||||
|
||||
// RemoteAddr: IP:port
|
||||
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err == nil {
|
||||
return host
|
||||
}
|
||||
|
||||
return r.RemoteAddr
|
||||
}
|
||||
|
||||
func BuildFileUrl(path *string) string {
|
||||
if path == nil || *path == "" {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user