feat: 统一sql命名、函数命名

This commit is contained in:
2026-08-02 12:02:04 +08:00
parent d39342ce5f
commit 0e674e9d56
68 changed files with 1985 additions and 1720 deletions

View File

@@ -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 ""