|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"git.diulo.com/mogfee/kit/transport/http"
|
|
|
|
"git.diulo.com/mogfee/kit/middleware/jwt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type UserHTTPServer interface {
|
|
|
|
List(context.Context, *LoginRequest) (*LoginResponse, error)
|
|
|
|
Login(context.Context, *LoginRequest) (*LoginResponse, error)
|
|
|
|
Delete(context.Context, *LoginRequest) (*LoginResponse, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RegisterUserHTTPServer(s *http.Server, srv UserServer) {
|
|
|
|
r := s.Route("/")
|
|
|
|
r.GET("/api/v1/user/list", _User_List0_HTTP_Handler(srv))
|
|
|
|
r.GET("/api/v1/user/login", _User_Login0_HTTP_Handler(srv))
|
|
|
|
}
|
|
|
|
func _User_List0_HTTP_Handler(srv UserHTTPServer) func(ctx http.Context) error {
|
|
|
|
return func(ctx http.Context) error {
|
|
|
|
var in LoginRequest
|
|
|
|
//user:list
|
|
|
|
var newCtx context.Context = ctx
|
|
|
|
newCtx = jwt.SetAuthKeyContext(newCtx, "user:list")
|
|
|
|
newCtx = jwt.SetNeedAuthContext(newCtx, true)
|
|
|
|
if err := ctx.BindQuery(&in); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
http.SetOperation(ctx, "/com.diulo.api.user/list")
|
|
|
|
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
|
|
return srv.List(ctx, req.(*LoginRequest))
|
|
|
|
})
|
|
|
|
out, err := h(newCtx, &in)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
reply := out.(*LoginResponse)
|
|
|
|
return ctx.Result(200, reply)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func _User_Login0_HTTP_Handler(srv UserHTTPServer) func(ctx http.Context) error {
|
|
|
|
return func(ctx http.Context) error {
|
|
|
|
var in LoginRequest
|
|
|
|
var newCtx context.Context = ctx
|
|
|
|
newCtx = jwt.SetNeedAuthContext(newCtx, true)
|
|
|
|
if err := ctx.BindQuery(&in); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
http.SetOperation(ctx, "/com.diulo.api.user/login")
|
|
|
|
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
|
|
return srv.Login(ctx, req.(*LoginRequest))
|
|
|
|
})
|
|
|
|
out, err := h(newCtx, &in)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
reply := out.(*LoginResponse)
|
|
|
|
return ctx.Result(200, reply)
|
|
|
|
}
|
|
|
|
}
|