You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1 KiB
Go

/**
* @Author: jager
* @Email: lhj168os@gmail.com
* @File: api
* @Date: 2021/12/31 2:34 下午
* @package: api
* @Version: v1.0.0
*
* @Description:
*
*/
package api
import (
"github.com/jageros/hawox/jwt"
"idata/internal/service/almanac"
"idata/internal/service/soup"
"idata/internal/service/user"
"github.com/gin-gonic/gin"
"github.com/jageros/hawox/errcode"
"github.com/jageros/hawox/httpx"
)
func Registry(engine *gin.Engine) {
r := engine.Group("/haw")
ur := r.Group("/user")
ur.POST("/register", user.Register)
ur.POST("/login", user.Login)
ur.GET("/info", jwt.CheckToken, user.Info)
ur.GET("/secret", jwt.CheckToken, user.Secret)
ur.GET("/open", jwt.CheckToken, user.OpenApi)
apiR := r.Group("/api", auth)
apiR.GET("/soup", soup.GetRandSoup)
apiR.GET("/almanac", almanac.Almanac)
}
func auth(ctx *gin.Context) {
uid, ok1 := httpx.DecodeUrlVal(ctx, "uid")
secret, ok2 := httpx.DecodeUrlVal(ctx, "secret")
if !ok1 || !ok2 {
httpx.ErrInterrupt(ctx, errcode.InvalidParam)
return
}
if !user.Auth(uid, secret) {
httpx.ErrInterrupt(ctx, errcode.VerifyErr)
return
}
}