server/pkg/modules/user/user-handler.go

44 lines
1.0 KiB
Go
Raw Permalink Normal View History

2019-11-11 15:00:04 +00:00
package user
import (
"fmt"
"reflect"
"github.com/valyala/fasthttp"
2019-11-13 14:21:05 +00:00
"git.loafle.net/loafer/annotation-go"
"git.loafle.net/loafer/di-go"
2019-11-11 15:00:04 +00:00
// For annotation
_ "git.loafle.net/totopia/server/pkg/loafer/web/annotation"
)
var UserHandlerType = reflect.TypeOf((*UserHandler)(nil))
func init() {
2019-11-13 14:21:05 +00:00
di.RegisterType(UserHandlerType)
2019-11-11 15:00:04 +00:00
}
type UserHandler struct {
2019-11-13 14:21:05 +00:00
annotation.TypeAnnotation `annotation:"@web:RestHandler(\"entry\": \"/users\")"`
2019-11-11 15:00:04 +00:00
2019-11-13 14:21:05 +00:00
_List annotation.MethodAnnotation `annotation:"@web:RequestMapping(\"method\": \"GET\", \"params\": [])"`
_Detail annotation.MethodAnnotation `annotation:"@web:RequestMapping(\"method\": \"GET\", \"entry\": \"/:id\", \"params\":[\"userId\"])"`
2019-11-11 15:00:04 +00:00
UserService *UserService `annotation:"@Inject()"`
}
func (us *UserHandler) List(ctx *fasthttp.RequestCtx) error {
2019-11-14 15:53:14 +00:00
fmt.Fprintf(ctx, "List hello, %s!\n", ctx.UserValue("id"))
2019-11-11 15:00:04 +00:00
2019-11-14 15:57:53 +00:00
us.UserService.FindAll()
2019-11-11 15:00:04 +00:00
return nil
}
2019-11-14 15:53:14 +00:00
func (us *UserHandler) Detail(ctx *fasthttp.RequestCtx) error {
fmt.Fprintf(ctx, "Detail hello, %s!\n", ctx.UserValue("id"))
2019-11-11 15:00:04 +00:00
return nil
}