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