mirror of
https://github.com/simon-ding/polaris.git
synced 2026-04-21 03:07:30 +08:00
first draft version
This commit is contained in:
36
server/common.go
Normal file
36
server/common.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"polaris/log"
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func HttpHandler(f func(*gin.Context) (interface{}, error)) gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
|
||||
r, err := f(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(200, Response{
|
||||
Code: 1,
|
||||
Message: fmt.Sprintf("%v", err),
|
||||
})
|
||||
return
|
||||
}
|
||||
log.Infof("url %v return: %+v", ctx.Request.URL, r)
|
||||
|
||||
ctx.JSON(200, Response{
|
||||
Code: 0,
|
||||
Message: "success",
|
||||
Data: r,
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
Reference in New Issue
Block a user