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