biu: Index | Files

package box

import ""


Package Files

ctx.go type.go


const (
    BiuAttrErr        = "__BIU_ERROR__"
    BiuAttrErrCode    = "__BIU_ERROR_CODE__"
    BiuAttrErrMsg     = "__BIU_ERROR_MESSAGE__"
    BiuAttrErrArgs    = "__BIU_ERROR_ARGS__"
    BiuAttrRouteID    = "__BIU_ROUTE_ID__"
    BiuAttrAuthUserID = "__BIU_AUTH_USER_ID__"
    BiuAttrEntities   = "__BIU_ENTITIES__"
const CtxSignature = ""
const FileSignature = ""

type CommonResp Uses

type CommonResp struct {
    Code    int         `json:"code"`
    Message string      `json:"message"`
    Data    interface{} `json:"data"`
    RouteID string      `json:"route_id,omitempty"`

CommonResp with code, message and data

type Ctx Uses

type Ctx struct {
    ErrCatcher errc.Catcher
    Logger     log.ILogger

Ctx wrap *restful.Request and *restful.Response in one struct.

func (*Ctx) Bind Uses

func (ctx *Ctx) Bind(obj interface{}) error

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) BindJSON Uses

func (ctx *Ctx) BindJSON(obj interface{}) error

BindJSON is a shortcut for ctx.BindWith(obj, binding.JSON).

func (*Ctx) BindQuery Uses

func (ctx *Ctx) BindQuery(obj interface{}) error

BindQuery is a shortcut for ctx.BindWith(obj, binding.Query).

func (*Ctx) BindWith Uses

func (ctx *Ctx) BindWith(obj interface{}, b binding.Binding) error

BindWith binds the passed struct pointer using the specified binding engine. See the binding package.

func (*Ctx) BodyParameterValues Uses

func (ctx *Ctx) BodyParameterValues(name string) ([]string, error)

BodyParameterValues returns the array of parameter in a POST form body.

func (*Ctx) ContainsError Uses

func (ctx *Ctx) ContainsError(err error, code int, v ...interface{}) bool

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) Form Uses

func (ctx *Ctx) Form(name string) param.Parameter

Form reads form parameter with name.

func (*Ctx) Header Uses

func (ctx *Ctx) Header(name string) param.Parameter

Header reads header parameter with name.

func (*Ctx) Host Uses

func (ctx *Ctx) Host() string

Host returns the host of request.

func (*Ctx) IP Uses

func (ctx *Ctx) IP() string

IP returns the IP address of request.

func (*Ctx) IsLogin Uses

func (ctx *Ctx) IsLogin(i ...*auth.Instance) (userID string, err error)

IsLogin gets JWT token in request by OAuth2Extractor, and parse it with CheckToken.

func (*Ctx) Must Uses

func (ctx *Ctx) Must(err error, code int, v ...interface{})

Must causes a return from a function if err is not nil.

func (*Ctx) MustBind Uses

func (ctx *Ctx) MustBind(obj interface{}, code int, v ...interface{})

MustBind is a shortcur for ctx.Must(ctx.Bind(obj), code, v...)

func (*Ctx) MustBindJSON Uses

func (ctx *Ctx) MustBindJSON(obj interface{}, code int, v ...interface{})

MustBindJSON is a shortcur for ctx.Must(ctx.BindJSON(obj), code, v...)

func (*Ctx) MustBindQuery Uses

func (ctx *Ctx) MustBindQuery(obj interface{}, code int, v ...interface{})

MustBindQuery is a shortcur for ctx.Must(ctx.BindQuery(obj), code, v...)

func (*Ctx) MustBindWith Uses

func (ctx *Ctx) MustBindWith(obj interface{}, b binding.Binding, code int, v ...interface{})

MustBindWith is a shortcur for ctx.Must(ctx.BindWith(obj, b), code, v...)

func (*Ctx) Next Uses

func (ctx *Ctx) Next()

func (*Ctx) Path Uses

func (ctx *Ctx) Path(name string) param.Parameter

Path reads path parameter with name.

func (*Ctx) Proxy Uses

func (ctx *Ctx) Proxy() []string

Proxy returns the proxy endpoints behind a request.

func (*Ctx) Query Uses

func (ctx *Ctx) Query(name string) param.Parameter

Query reads query parameter with name.

func (*Ctx) Redirect Uses

func (ctx *Ctx) Redirect(url string, code int)

Redirect replies to the request with a redirect to url.

func (Ctx) Req Uses

func (ctx Ctx) Req() *http.Request

Req returns http.Request of ctx.

func (Ctx) Resp Uses

func (ctx Ctx) Resp() http.ResponseWriter

Resp returns http.ResponseWriter of ctx.

func (*Ctx) ResponseError Uses

func (ctx *Ctx) ResponseError(code int, msg string)

ResponseError is a convenience method to response an error code and message.

func (*Ctx) ResponseJSON Uses

func (ctx *Ctx) ResponseJSON(v ...interface{})

ResponseJSON is a convenience method for writing a value wrap in CommonResp as JSON.

func (*Ctx) ResponseStdErrCode Uses

func (ctx *Ctx) ResponseStdErrCode(code int, v ...interface{})

ResponseStdErrCode is a convenience method response a code with msg in Code Desc.

func (*Ctx) RouteID Uses

func (ctx *Ctx) RouteID() string

RouteID returns the RouteID of current route.

func (*Ctx) RouteSignature Uses

func (ctx *Ctx) RouteSignature() string

RouteSignature returns the signature of current route. Example: /v1/user/login POST

func (*Ctx) Transform Uses

func (ctx *Ctx) Transform(f func(...interface{}) []interface{})

func (*Ctx) UserID Uses

func (ctx *Ctx) UserID() string

UserID returns UserID stored in attribute.

type File Uses

type File struct {
    Header *multipart.FileHeader

Package box imports 13 packages (graph) and is imported by 4 packages. Updated 2020-02-04. Refresh now. Tools for package owners.