Documentation
¶
Index ¶
- Constants
- type CommonResp
- type Ctx
- func (ctx *Ctx) Bind(obj any) error
- func (ctx *Ctx) BindJSON(obj any) error
- func (ctx *Ctx) BindQuery(obj any) error
- func (ctx *Ctx) BindWith(obj any, b binding.Binding) error
- func (ctx *Ctx) BodyParameterValues(name string) ([]string, error)
- func (ctx *Ctx) ContainsError(err error, code int, v ...any) bool
- func (ctx *Ctx) Form(name string) param.Parameter
- func (ctx *Ctx) Header(name string) param.Parameter
- func (ctx *Ctx) Host() string
- func (ctx *Ctx) IP() string
- func (ctx *Ctx) IsLogin(ck *auth.Instance) (userID string, err error)
- func (ctx *Ctx) Must(err error, code int, v ...any)
- func (ctx *Ctx) MustBind(obj any, code int, v ...any)
- func (ctx *Ctx) MustBindJSON(obj any, code int, v ...any)
- func (ctx *Ctx) MustBindQuery(obj any, code int, v ...any)
- func (ctx *Ctx) MustBindWith(obj any, b binding.Binding, code int, v ...any)
- func (ctx *Ctx) Next()
- func (ctx *Ctx) Path(name string) param.Parameter
- func (ctx *Ctx) Proxy() []string
- func (ctx *Ctx) Query(name string) param.Parameter
- func (ctx *Ctx) Redirect(url string, code int)
- func (ctx *Ctx) Req() *http.Request
- func (ctx *Ctx) Resp() http.ResponseWriter
- func (ctx *Ctx) ResponseError(code int, msg string)
- func (ctx *Ctx) ResponseJSON(v ...any)
- func (ctx *Ctx) ResponseStdErrCode(code int, v ...any)
- func (ctx *Ctx) RouteID() string
- func (ctx *Ctx) RouteSignature() string
- func (ctx *Ctx) Transform(f func(...any) []any)
- func (ctx *Ctx) UserID() string
- func (ctx *Ctx) VdErr() error
- type File
Constants ¶
const ( BiuAttrErr = "__BIU_ERROR__" BiuAttrErrLine = "__BIU_ERROR_LINE__" BiuAttrErrCode = "__BIU_ERROR_CODE__" BiuAttrErrMsg = "__BIU_ERROR_MESSAGE__" BiuAttrErrArgs = "__BIU_ERROR_ARGS__" BiuAttrRouteID = "__BIU_ROUTE_ID__" BiuAttrAuthUserID = "__BIU_AUTH_USER_ID__" BiuAttrEntities = "__BIU_ENTITIES__" BiuAttrVdErr = "__BIU_VALIDATE_ERROR_" )
const CtxSignature = "github.com/tuotoo/biu/box.Ctx"
const FileSignature = "github.com/tuotoo/biu/box.File"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommonResp ¶
type CommonResp struct { Code int `json:"code"` Message string `json:"message"` Data any `json:"data"` RouteID string `json:"route_id,omitempty"` }
CommonResp with code, message and data
type Ctx ¶
type Ctx struct { *restful.Request *restful.Response *restful.FilterChain ErrCatcher errc.Catcher Logger *slog.Logger }
Ctx wrap *restful.Request and *restful.Response in one struct.
func (*Ctx) Bind ¶
Bind checks the Content-Type to select a binding engine automatically, Depending the "Content-Type" header different bindings are used:
"application/json" --> JSON binding "application/xml" --> XML binding
otherwise --> returns an error. It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input. It decodes the json payload into the struct specified as a pointer. It writes a 400 error and sets Content-Type header "text/plain" in the response if input is not valid.
func (*Ctx) BindWith ¶
BindWith binds the passed struct pointer using the specified binding engine. See the binding package.
func (*Ctx) BodyParameterValues ¶
BodyParameterValues returns the array of parameter in a POST form body.
func (*Ctx) ContainsError ¶
ContainsError is a convenience method to check error is nil. If error is nil, it will return false, else it will log the error, make a CommonResp response and return true. if code is 0, it will use err.Error() as CommonResp.message.
func (*Ctx) IsLogin ¶
IsLogin gets JWT token in request by OAuth2Extractor, and parse it with CheckToken.
func (*Ctx) MustBindJSON ¶
MustBindJSON is a shortcut for ctx.Must(ctx.BindJSON(obj), code, v...)
func (*Ctx) MustBindQuery ¶
MustBindQuery is a shortcut for ctx.Must(ctx.BindQuery(obj), code, v...)
func (*Ctx) MustBindWith ¶
MustBindWith is a shortcut for ctx.Must(ctx.BindWith(obj, b), code, v...)
func (*Ctx) Resp ¶ added in v0.4.4
func (ctx *Ctx) Resp() http.ResponseWriter
Resp returns http.ResponseWriter of ctx.
func (*Ctx) ResponseError ¶
ResponseError is a convenience method to response an error code and message.
func (*Ctx) ResponseJSON ¶
ResponseJSON is a convenience method for writing a value wrap in CommonResp as JSON.
func (*Ctx) ResponseStdErrCode ¶
ResponseStdErrCode is a convenience method response a code with msg in Code Desc.
func (*Ctx) RouteSignature ¶
RouteSignature returns the signature of current route. Example: /v1/user/login POST