Init: bootstrap go module

This commit is contained in:
2025-09-04 11:01:05 +08:00
commit 6d7074198f
20 changed files with 658 additions and 0 deletions

23
utils/getRemoteAddr.go Normal file
View File

@@ -0,0 +1,23 @@
package utils
import (
"net"
"github.com/uptrace/bunrouter"
)
func GetRemoteAddr(req bunrouter.Request) string {
xForwardedFor := req.Header.Get("X-Forwarded-For")
xRealIP := req.Header.Get("X-Real-IP")
if xForwardedFor != "" {
return xForwardedFor
}
if xRealIP != "" {
return xRealIP
}
host, _, _ := net.SplitHostPort(req.RemoteAddr)
return host
}

14
utils/success.go Normal file
View File

@@ -0,0 +1,14 @@
package utils
import (
"io"
"net/http"
)
func Success(w http.ResponseWriter) error {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "text/plain")
_, err := io.WriteString(w,
`{"code":200, "message": "success"}`+"\n")
return err
}