gintool

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2020 License: MIT Imports: 13 Imported by: 0

README

gintool

tools for web framework gin

Documentation

Index

Constants

View Source
const (
	CodeOKZero         = 0
	CodeOK             = 2000
	CodeCreated        = 2001
	CodePartialContent = 2006

	CodeMultipleChoices   = 3000
	CodeMovedPermanently  = 3001
	CodeFound             = 3002
	CodeSeeOther          = 3003
	CodeNotModified       = 3004
	CodeUseProxy          = 3005
	CodeTemporaryRedirect = 3007
	CodePermanentRedirect = 3008

	CodeBadRequest      = 4000
	CodeUnauthorized    = 4001
	CodeForbidden       = 4003
	CodeNotFound        = 4004
	CodeTooManyRequests = 4029
	CodeValidateErr     = 4050

	CodeInternalErr        = 5000
	CodeServiceUnavailable = 5003
	CodeParseDataErr       = 5013
	CodeDBErr              = 5014
	CodeHbaseErr           = 5015
	CodeRedisErr           = 5016
	CodeDiskErr            = 5017
	CodeNSQErr             = 5030
	CodeKafkaErr           = 5031
	CodeBindErr            = 5040
	CodeEncodeErr          = 5041
	CodeDownstreamErr      = 5100
)
View Source
const (
	BValidator = 1 << iota
	BHeader
	BParam
	BJSONBody
	BXMLBody
	BFormQuery
	BFormBody
	BFormQueryBody
	BPBBody
	BMsgpackBody
)
View Source
const (
	KeyRequestID = "gintool_request_id"
)
View Source
const (
	UnknownStatus = 900
)

Variables

This section is empty.

Functions

func AbortWithCodeErr

func AbortWithCodeErr(c *gin.Context, code int, err error)

func AcquireBuffer

func AcquireBuffer() *bytes.Buffer

func Bind

func Bind(c *gin.Context, v interface{}, flag int) (err error)

func BindHeader

func BindHeader(c *gin.Context, v interface{}) error

BindHeader needs tag "header" in fields of v. The value of tag "header" is automatically converted to the canonical format.

func BindParam

func BindParam(c *gin.Context, v interface{}) error

BindParam needs tag "param" in fields of v.

func CloseGinValidator

func CloseGinValidator()

func CodeMsg

func CodeMsg(code int) string

func EncodeJSON

func EncodeJSON(v interface{}) (*bytes.Buffer, error)

EncodeJSON needs tag "json" in fields of v. Note: ReleaseBuffer needs to be called after EncodeJSON is called successfully.

func EncodeValues

func EncodeValues(v interface{}) (url.Values, error)

EncodeValues needs tag "url" in fields of v.

func FinishWithCodeData

func FinishWithCodeData(c *gin.Context, code int, data interface{})

func FormBindBody

func FormBindBody(c *gin.Context, v interface{}) error

FormBindBody needs tag "form" in fields of v.

func FormBindQuery

func FormBindQuery(c *gin.Context, v interface{}) error

FormBindQuery needs tag "form" in fields of v.

func FormBindQueryBody

func FormBindQueryBody(c *gin.Context, v interface{}) error

FormBindQueryBody needs tag "form" in fields of v.

func GetRequestHost

func GetRequestHost(req *http.Request) (host string)

func GetRequestID

func GetRequestID(c *gin.Context) string

func HTTPStatus

func HTTPStatus(code int) int

func HeaderBool

func HeaderBool(c *gin.Context, key string) (bool, error)

func HeaderInt64

func HeaderInt64(c *gin.Context, key string) (int64, error)

func HeaderString

func HeaderString(c *gin.Context, key string) (string, error)

func HeaderUint64

func HeaderUint64(c *gin.Context, key string) (uint64, error)

func IsGintoolError

func IsGintoolError(err error) bool

func JSONBindBody

func JSONBindBody(c *gin.Context, v interface{}) error

func JSONUseNumber

func JSONUseNumber(enabled bool)

func MsgpackBindBody

func MsgpackBindBody(c *gin.Context, v interface{}) error

func MustBind

func MustBind(c *gin.Context, v interface{}, flag int, cbs ...CallbackFunc)

func MustBindHeader

func MustBindHeader(c *gin.Context, v interface{}, cbs ...CallbackFunc)

func MustBindParam

func MustBindParam(c *gin.Context, v interface{}, cbs ...CallbackFunc)

func MustDo

func MustDo(run RunFunc, codes ...int) interface{}

func MustDoCallback

func MustDoCallback(run RunFunc, code int, cbs ...CallbackFunc) interface{}

MustDoCallback will call cbs if and only if run has error.

func MustEncodeJSON

func MustEncodeJSON(v interface{}, cbs ...CallbackFunc) *bytes.Buffer

MustEncodeJSON needs tag "json" in fields of v. Note: ReleaseBuffer needs to be called after MustEncodeJSON is called successfully.

func MustEncodeValues

func MustEncodeValues(v interface{}, cbs ...CallbackFunc) url.Values

func MustFormBindBody

func MustFormBindBody(c *gin.Context, v interface{}, cbs ...CallbackFunc)

func MustFormBindQuery

func MustFormBindQuery(c *gin.Context, v interface{}, cbs ...CallbackFunc)

func MustFormBindQueryBody

func MustFormBindQueryBody(c *gin.Context, v interface{}, cbs ...CallbackFunc)

func MustHeaderBool

func MustHeaderBool(c *gin.Context, key string, cbs ...CallbackFunc) bool

func MustHeaderInt64

func MustHeaderInt64(c *gin.Context, key string, cbs ...CallbackFunc) int64

func MustHeaderString

func MustHeaderString(c *gin.Context, key string, cbs ...CallbackFunc) string

func MustHeaderUInt64

func MustHeaderUInt64(c *gin.Context, key string, cbs ...CallbackFunc) uint64

func MustJSONBindBody

func MustJSONBindBody(c *gin.Context, v interface{}, cbs ...CallbackFunc)

func MustMsgpackBindBody

func MustMsgpackBindBody(c *gin.Context, v interface{}, cbs ...CallbackFunc)

func MustPBBindBody

func MustPBBindBody(c *gin.Context, v interface{}, cbs ...CallbackFunc)

func MustParamBool

func MustParamBool(c *gin.Context, key string, cbs ...CallbackFunc) bool

func MustParamInt64

func MustParamInt64(c *gin.Context, key string, cbs ...CallbackFunc) int64

func MustParamString

func MustParamString(c *gin.Context, key string, cbs ...CallbackFunc) string

func MustParamUInt64

func MustParamUInt64(c *gin.Context, key string, cbs ...CallbackFunc) uint64

func MustPostFormBool

func MustPostFormBool(c *gin.Context, key string, cbs ...CallbackFunc) bool

func MustPostFormInt64

func MustPostFormInt64(c *gin.Context, key string, cbs ...CallbackFunc) int64

func MustPostFormString

func MustPostFormString(c *gin.Context, key string, cbs ...CallbackFunc) string

func MustPostFormUInt64

func MustPostFormUInt64(c *gin.Context, key string, cbs ...CallbackFunc) uint64

func MustQueryBool

func MustQueryBool(c *gin.Context, key string, cbs ...CallbackFunc) bool

func MustQueryInt64

func MustQueryInt64(c *gin.Context, key string, cbs ...CallbackFunc) int64

func MustQueryString

func MustQueryString(c *gin.Context, key string, cbs ...CallbackFunc) string

func MustQueryUInt64

func MustQueryUInt64(c *gin.Context, key string, cbs ...CallbackFunc) uint64

func MustValidate

func MustValidate(v interface{}, cbs ...CallbackFunc)

func MustXMLBindBody

func MustXMLBindBody(c *gin.Context, v interface{}, cbs ...CallbackFunc)

func PBBindBody

func PBBindBody(c *gin.Context, v interface{}) error

func ParamBool

func ParamBool(c *gin.Context, key string) (bool, error)

func ParamInt64

func ParamInt64(c *gin.Context, key string) (int64, error)

func ParamString

func ParamString(c *gin.Context, key string) (string, error)

func ParamUint64

func ParamUint64(c *gin.Context, key string) (uint64, error)

func PostFormBool

func PostFormBool(c *gin.Context, key string) (bool, error)

func PostFormInt64

func PostFormInt64(c *gin.Context, key string) (int64, error)

func PostFormString

func PostFormString(c *gin.Context, key string) (string, error)

func PostFormUint64

func PostFormUint64(c *gin.Context, key string) (uint64, error)

func QueryBool

func QueryBool(c *gin.Context, key string) (bool, error)

func QueryInt64

func QueryInt64(c *gin.Context, key string) (int64, error)

func QueryString

func QueryString(c *gin.Context, key string) (string, error)

func QueryUint64

func QueryUint64(c *gin.Context, key string) (uint64, error)

func RegisterCode

func RegisterCode(code int, msg string, status int) bool

func ReleaseBuffer

func ReleaseBuffer(buffer *bytes.Buffer)

func ReleaseGintoolError

func ReleaseGintoolError(e *GintoolError)

func SetRequestID

func SetRequestID(f func(*gin.Context) string) gin.HandlerFunc

func Validate

func Validate(v interface{}) error

BindValidator needs tag "valid" in fields of v.

func XMLBindBody

func XMLBindBody(c *gin.Context, v interface{}) error

Types

type CallbackFunc

type CallbackFunc func(error)

type CommonResponse

type CommonResponse struct {
	RequestID string      `json:"request_id,omitempty"`
	Code      int         `json:"code"`
	Message   string      `json:"message"`
	Data      interface{} `json:"data,omitempty"`
}

func RespError

func RespError(id string, code int, err error) *CommonResponse

func RespOK

func RespOK(id string, code int, data interface{}) *CommonResponse

type Context

type Context struct {
	// contains filtered or unexported fields
}

func (*Context) Abort

func (c *Context) Abort(code int, err error)

func (*Context) Finish

func (c *Context) Finish(code int, data interface{})

func (*Context) GetCode

func (c *Context) GetCode() int

func (*Context) GetData

func (c *Context) GetData() interface{}

func (*Context) GetError

func (c *Context) GetError() error

func (*Context) IsOK

func (c *Context) IsOK() bool

func (*Context) String

func (c *Context) String() string

type EmptyError

type EmptyError struct {
	// contains filtered or unexported fields
}

func NewEmptyError

func NewEmptyError(kind Kind, key string) *EmptyError

func NewHeaderEmptyError

func NewHeaderEmptyError(key string) *EmptyError

func NewParamEmptyError

func NewParamEmptyError(key string) *EmptyError

func NewPostFormEmptyError

func NewPostFormEmptyError(key string) *EmptyError

func NewQueryEmptyError

func NewQueryEmptyError(key string) *EmptyError

func (EmptyError) Error

func (e EmptyError) Error() string

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(opts ...Option) *Engine

func (*Engine) GinHandler

func (e *Engine) GinHandler(handlers ...HandlerFunc) gin.HandlerFunc

func (*Engine) Use

func (e *Engine) Use(middlewares ...HandlerFunc) *Engine

type GintoolError

type GintoolError struct {
	// contains filtered or unexported fields
}

func AcquireGintoolError

func AcquireGintoolError(code int, err error) (e *GintoolError)

func (GintoolError) Error

func (e GintoolError) Error() string

func (GintoolError) GetCode

func (e GintoolError) GetCode() int

func (GintoolError) GetError

func (e GintoolError) GetError() error

type HandlerFunc

type HandlerFunc func(*gin.Context, *Context)

func GetCommonAborter

func GetCommonAborter() HandlerFunc

func GetCommonFinisher

func GetCommonFinisher() HandlerFunc

type HandlerFuncsChain

type HandlerFuncsChain []HandlerFunc

type Kind

type Kind int
const (
	KindHeader Kind = iota
	KindParam
	KindQuery
	KindPostForm
)

func (Kind) String

func (k Kind) String() string

type Option

type Option func(*Engine)

func WithAborter

func WithAborter(aborter HandlerFunc) Option

func WithFinisher

func WithFinisher(finisher HandlerFunc) Option

type RunFunc

type RunFunc func() (interface{}, error)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL