Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( RequestKey = requestKey{} ResponseKey = responseKey{} GinContextKey = ginContextKey{} )
Functions ¶
func New ¶
func New(method interface{}) gin.HandlerFunc
New example:
func Hello(ctx context.Context, req *proto.HelloHandlerReq) (*proto.HelloHandlerResp, error) { resp := proto.HelloHandlerResp{} resp.Welcome = fmt.Sprintf("hello, %s!", req.Name) return &resp, nil }
func NewWithOptions ¶
func NewWithOptions(method interface{}, options ...Option) gin.HandlerFunc
Types ¶
type Option ¶
type Option func(config *config)
func DisableReturn ¶
func DisableReturn() Option
DisableReturn handler return nothing, which means it will not automatically respond to a response or error. sometimes use both "disableRet" and "ginCtx"
example:
func HelloWithGinCtxAndNoResponse(ctx *gin.Context, req *proto.HelloHandlerReq) { var err error if err != nil { return err } resp := proto.HelloHandlerResp{} resp.Welcome = fmt.Sprintf("hello, %s! the uri is %s", req.Name, c.Request.RequestURI) c.JSON(http.StatusOK, resp) }
func WithContext ¶
func WithContext() Option
WithContext handler func must in 3 params, and the third param must be *gin.Context
example:
func (h *HelloHandler) HelloWithGinCtx(ctx context.Context, req *proto.HelloHandlerReq, c *gin.Context) (*proto.HelloHandlerResp, error) { resp := proto.HelloHandlerResp{} resp.Welcome = fmt.Sprintf("hello, %s! the uri is %s", req.Name, c.Request.RequestURI) return &resp, nil }
func WithResult ¶
func WithResult() Option
WithResult handler func must return 1 param and the type must be *result.Result
example:
func HelloWithResult(ctx context.Context, req *proto.HelloHandlerReq) *result.Result { resp := proto.HelloHandlerResp{} resp.Welcome = fmt.Sprintf("hello, %s!", req.Name) return result.Succeed(resp) }
Click to show internal directories.
Click to hide internal directories.