You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.echinacities.com/mogfee/protoc-gen-kit/response"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RegisterUserHandler(app *gin.Engine, srv UserServer) {
|
|
|
|
app.GET("/api/v1/user/list", httpListHandler(srv))
|
|
|
|
app.POST("/api/v1/user/login", httpLoginHandler(srv))
|
|
|
|
}
|
|
|
|
func httpListHandler(srv UserServer) func(c *gin.Context) {
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
post := LoginRequest{}
|
|
|
|
resp := response.New(c)
|
|
|
|
if err := resp.BindQuery(&post); err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
result, err := srv.List(c, &post)
|
|
|
|
if err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
resp.Success(result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func httpLoginHandler(srv UserServer) func(c *gin.Context) {
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
post := LoginRequest{}
|
|
|
|
resp := response.New(c)
|
|
|
|
if err := resp.BindJSON(&post); err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
result, err := srv.Login(c, &post)
|
|
|
|
if err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
resp.Success(result)
|
|
|
|
}
|
|
|
|
}
|