合作页面的内容
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/lionsoul2014/ip2region/binding/golang/xdb"
|
||||
@@ -27,7 +25,7 @@ func InitIP2Region(dbPath string) {
|
||||
return
|
||||
}
|
||||
|
||||
searcher, err = xdb.NewWithBuffer(cBuff)
|
||||
searcher, err = xdb.NewWithBuffer(nil, cBuff)
|
||||
if err != nil {
|
||||
log.Printf("Failed to create searcher: %v", err)
|
||||
return
|
||||
|
||||
55
server/utils/response.go
Normal file
55
server/utils/response.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Response 统一响应结构
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Result interface{} `json:"result"`
|
||||
}
|
||||
|
||||
// Success 成功响应 (Code 200)
|
||||
func Success(c *gin.Context, result interface{}) {
|
||||
c.JSON(http.StatusOK, Response{
|
||||
Code: 200,
|
||||
Message: "Success",
|
||||
Result: result,
|
||||
})
|
||||
}
|
||||
|
||||
// SuccessWithMsg 自定义消息成功响应
|
||||
func SuccessWithMsg(c *gin.Context, msg string, result interface{}) {
|
||||
c.JSON(http.StatusOK, Response{
|
||||
Code: 200,
|
||||
Message: msg,
|
||||
Result: result,
|
||||
})
|
||||
}
|
||||
|
||||
// Error 错误响应 (默认 Code 400)
|
||||
func Error(c *gin.Context, code int, msg string) {
|
||||
httpStatus := http.StatusBadRequest
|
||||
if code == 500 {
|
||||
httpStatus = http.StatusInternalServerError
|
||||
}
|
||||
|
||||
c.JSON(httpStatus, Response{
|
||||
Code: code,
|
||||
Message: msg,
|
||||
Result: nil,
|
||||
})
|
||||
}
|
||||
|
||||
// ServerError 服务器错误 (Code 500)
|
||||
func ServerError(c *gin.Context, err error) {
|
||||
c.JSON(http.StatusInternalServerError, Response{
|
||||
Code: 500,
|
||||
Message: err.Error(),
|
||||
Result: nil,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user