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.

60 lines
1.7 KiB

2 years ago
package user
import (
2 years ago
"context"
2 years ago
"git.diulo.com/mogfee/kit/transport/http"
2 years ago
"git.diulo.com/mogfee/kit/middleware/jwt"
2 years ago
)
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.POST("/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
2 years ago
//user:search
2 years ago
var newCtx context.Context = ctx
newCtx = jwt.SetAuthKeyContext(ctx, "user:search")
2 years ago
if err := ctx.BindQuery(&in); err != nil {
return err
}
2 years ago
http.SetOperation(ctx, "/com.diulo.api.user/list")
2 years ago
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.List(ctx, req.(*LoginRequest))
})
2 years ago
out, err := h(newCtx, &in)
2 years ago
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
2 years ago
var newCtx context.Context = ctx
2 years ago
if err := ctx.Bind(&in); err != nil {
return err
}
2 years ago
http.SetOperation(ctx, "/com.diulo.api.user/login")
2 years ago
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.Login(ctx, req.(*LoginRequest))
})
2 years ago
out, err := h(newCtx, &in)
2 years ago
if err != nil {
return err
}
reply := out.(*LoginResponse)
return ctx.Result(200, reply)
}
}