提交 v1.3.0 beta
This commit is contained in:
@ -1,25 +1,23 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"next-terminal/server/constant"
|
||||
"github.com/labstack/echo/v4"
|
||||
"next-terminal/server/common/maps"
|
||||
"next-terminal/server/common/nt"
|
||||
"next-terminal/server/dto"
|
||||
"next-terminal/server/global/cache"
|
||||
"next-terminal/server/model"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type Map map[string]interface{}
|
||||
|
||||
func Fail(c echo.Context, code int, message string) error {
|
||||
return c.JSON(200, Map{
|
||||
return c.JSON(200, maps.Map{
|
||||
"code": code,
|
||||
"message": message,
|
||||
})
|
||||
}
|
||||
|
||||
func FailWithData(c echo.Context, code int, message string, data interface{}) error {
|
||||
return c.JSON(200, Map{
|
||||
return c.JSON(200, maps.Map{
|
||||
"code": code,
|
||||
"message": message,
|
||||
"data": data,
|
||||
@ -27,7 +25,7 @@ func FailWithData(c echo.Context, code int, message string, data interface{}) er
|
||||
}
|
||||
|
||||
func Success(c echo.Context, data interface{}) error {
|
||||
return c.JSON(200, Map{
|
||||
return c.JSON(200, maps.Map{
|
||||
"code": 1,
|
||||
"message": "success",
|
||||
"data": data,
|
||||
@ -35,11 +33,11 @@ func Success(c echo.Context, data interface{}) error {
|
||||
}
|
||||
|
||||
func GetToken(c echo.Context) string {
|
||||
token := c.Request().Header.Get(constant.Token)
|
||||
token := c.Request().Header.Get(nt.Token)
|
||||
if len(token) > 0 {
|
||||
return token
|
||||
}
|
||||
return c.QueryParam(constant.Token)
|
||||
return c.QueryParam(nt.Token)
|
||||
}
|
||||
|
||||
func GetCurrentAccount(c echo.Context) (*model.User, bool) {
|
||||
@ -50,20 +48,3 @@ func GetCurrentAccount(c echo.Context) (*model.User, bool) {
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func HasPermission(c echo.Context, owner string) bool {
|
||||
// 检测是否登录
|
||||
account, found := GetCurrentAccount(c)
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
// 检测是否为管理人员
|
||||
if constant.TypeAdmin == account.Type {
|
||||
return true
|
||||
}
|
||||
// 检测是否为所有者
|
||||
if owner == account.ID {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user