server/pkg/modules/user/user-handler.go
2019-11-13 23:21:05 +09:00

42 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, "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
}