server/pkg/modules/user/user-handler.go
2019-11-15 00:57:53 +09:00

44 lines
1.0 KiB
Go

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