feat: function CRUD operation is ready

This commit is contained in:
RockYang
2023-12-24 22:12:12 +08:00
parent 8addba8203
commit 3991f4daec
9 changed files with 71 additions and 30 deletions

View File

@@ -9,6 +9,8 @@ import (
"chatplus/utils"
"chatplus/utils/resp"
"github.com/golang-jwt/jwt/v5"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
@@ -104,3 +106,20 @@ func (h *FunctionHandler) Remove(c *gin.Context) {
}
resp.SUCCESS(c)
}
// GenToken generate function api access token
func (h *FunctionHandler) GenToken(c *gin.Context) {
// 创建 token
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"user_id": 0,
"expired": 0,
})
tokenString, err := token.SignedString([]byte(h.App.Config.Session.SecretKey))
if err != nil {
logger.Error("error with generate token", err)
resp.ERROR(c)
return
}
resp.SUCCESS(c, tokenString)
}