mirror of
https://github.com/AlistGo/alist.git
synced 2025-06-22 13:41:29 +08:00
chore: move server package to root
This commit is contained in:
44
server/common/common.go
Normal file
44
server/common/common.go
Normal file
@ -0,0 +1,44 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func ErrorResp(c *gin.Context, err error, code int, l ...bool) {
|
||||
if len(l) != 0 && l[0] {
|
||||
log.Errorf("%+v", err)
|
||||
}
|
||||
c.JSON(200, Resp{
|
||||
Code: code,
|
||||
Message: err.Error(),
|
||||
Data: nil,
|
||||
})
|
||||
c.Abort()
|
||||
}
|
||||
|
||||
func ErrorStrResp(c *gin.Context, str string, code int) {
|
||||
log.Error(str)
|
||||
c.JSON(200, Resp{
|
||||
Code: code,
|
||||
Message: str,
|
||||
Data: nil,
|
||||
})
|
||||
c.Abort()
|
||||
}
|
||||
|
||||
func SuccessResp(c *gin.Context, data ...interface{}) {
|
||||
if len(data) == 0 {
|
||||
c.JSON(200, Resp{
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
Data: nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(200, Resp{
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
Data: data[0],
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user