echotool

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: MIT Imports: 19 Imported by: 0

README

echotool

tools for echo which is a web framework in golang

Documentation

Index

Constants

View Source
const (
	BValidator = 1 << iota
	BHeader
	BParam
	BFormQuery
	BFormBody
	BFormQueryBody
	BJSONBody
	BXMLBody
	BProtobufBody
	BMsgpackBody
	BYAMLBody
)
View Source
const (
	CodeOKZero         = 0
	CodeOK             = 20000
	CodeCreated        = 20100
	CodePartialContent = 20600

	CodeMultipleChoices   = 30000
	CodeMovedPermanently  = 30100
	CodeFound             = 30200
	CodeSeeOther          = 30300
	CodeNotModified       = 30400
	CodeUseProxy          = 30500
	CodeTemporaryRedirect = 30700
	CodePermanentRedirect = 30800

	CodeBadRequest      = 40000
	CodeUnauthorized    = 40100
	CodeForbidden       = 40300
	CodeNotFound        = 40400
	CodeTooManyRequests = 42900
	CodeValidateErr     = 45000

	CodeInternalErr        = 50000
	CodeServiceUnavailable = 50300
	CodeParseDataErr       = 50013
	CodeMySQLErr           = 50014
	CodePostgreSQLErr      = 50015
	CodeRedisErr           = 50016
	CodeClickHouseErr      = 50017
	CodeNSQErr             = 50030
	CodeKafkaErr           = 50031
	CodeRocketMQErr        = 50032
	CodeBindErr            = 50040
	CodeEncodeErr          = 50041
	CodeDownstreamErr      = 50099
)
View Source
const (
	KeyRequestID = "x_request_id"
)
View Source
const (
	UnknownStatus = 999
)

Variables

This section is empty.

Functions

func AbortWithCodeErr

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

func AcquireBuffer

func AcquireBuffer() *bytes.Buffer

func Bind

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

func BindHeader

func BindHeader(c echo.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 echo.Context, v interface{}) error

BindParam needs tag "param" in fields of v.

func CodeMsg

func CodeMsg(code int) string

func CtxDebug added in v1.0.1

func CtxDebug(ec *Context, format string, args ...interface{})

func CtxDebugKV added in v1.0.3

func CtxDebugKV(ec *Context, msg string, fields ...zap.Field)

func CtxError added in v1.0.1

func CtxError(ec *Context, format string, args ...interface{})

func CtxErrorKV added in v1.0.3

func CtxErrorKV(ec *Context, msg string, fields ...zap.Field)

func CtxFatal added in v1.0.1

func CtxFatal(ec *Context, format string, args ...interface{})

CtxFatal logs a message, then calls os.Exit.

func CtxFatalKV added in v1.0.3

func CtxFatalKV(ec *Context, msg string, fields ...zap.Field)

CtxFatalKV logs a message, then calls os.Exit.

func CtxInfo added in v1.0.1

func CtxInfo(ec *Context, format string, args ...interface{})

func CtxInfoKV added in v1.0.3

func CtxInfoKV(ec *Context, msg string, fields ...zap.Field)

func CtxPanic added in v1.0.1

func CtxPanic(ec *Context, format string, args ...interface{})

CtxPanic logs a message, then panics.

func CtxPanicKV added in v1.0.3

func CtxPanicKV(ec *Context, msg string, fields ...zap.Field)

CtxPanicKV logs a message, then panics.

func CtxWarn added in v1.0.1

func CtxWarn(ec *Context, format string, args ...interface{})

func CtxWarnKV added in v1.0.3

func CtxWarnKV(ec *Context, msg string, fields ...zap.Field)

func Debug added in v1.0.2

func Debug(format string, args ...interface{})

func DebugKV added in v1.0.3

func DebugKV(msg string, fields ...zap.Field)

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 Error added in v1.0.2

func Error(format string, args ...interface{})

func ErrorKV added in v1.0.3

func ErrorKV(msg string, fields ...zap.Field)

func FasterJSONReflectedEncoder added in v1.0.3

func FasterJSONReflectedEncoder(w io.Writer) zapcore.ReflectedEncoder

func Fatal added in v1.0.2

func Fatal(format string, args ...interface{})

Fatal logs a message, then calls os.Exit.

func FatalKV added in v1.0.3

func FatalKV(msg string, fields ...zap.Field)

FatalKV logs a message, then calls os.Exit.

func FinishWithCodeData

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

func FlushLog added in v1.0.1

func FlushLog() error

FlushLog flushes any buffered log entries.

func ForceRegisterCode

func ForceRegisterCode(code int, msg string, status int)

ForceRegisterCode will force to cover codeMsg map and httpStatus map.

func FormBindBody

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

FormBindBody needs tag "form" in fields of v.

func FormBindQuery

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

FormBindQuery needs tag "form" in fields of v.

func FormBindQueryBody

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

FormBindQueryBody needs tag "form" in fields of v.

func FormBool

func FormBool(c echo.Context, key string) (bool, error)

func FormInt64

func FormInt64(c echo.Context, key string) (int64, error)

func FormString

func FormString(c echo.Context, key string) (string, error)

func FormUint64

func FormUint64(c echo.Context, key string) (uint64, error)

func GetHostname added in v1.0.1

func GetHostname() (host string)

func GetRequestHost

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

func GetRequestID

func GetRequestID(c echo.Context) string

func GetUUID

func GetUUID(c echo.Context) (u string)

func HTTPStatus

func HTTPStatus(code int) int

func HeaderBool

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

func HeaderInt64

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

func HeaderString

func HeaderString(c echo.Context, key string) (string, error)

func HeaderUint64

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

func Info added in v1.0.2

func Info(format string, args ...interface{})

func InfoKV added in v1.0.3

func InfoKV(msg string, fields ...zap.Field)

func IsEchotoolError

func IsEchotoolError(err error) bool

func IsEmptyError

func IsEmptyError(err error) bool

func JSONBindBody

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

JSONBindBody needs tag "json" in fields of v.

func MsgpackBindBody

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

MsgpackBindBody needs tag "msgpack" in fields of v.

func MustBind

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

func MustBindHeader

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

func MustBindParam

func MustBindParam(c echo.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 echo.Context, v interface{}, cbs ...CallbackFunc)

func MustFormBindQuery

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

func MustFormBindQueryBody

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

func MustFormBool

func MustFormBool(c echo.Context, key string, cbs ...CallbackFunc) bool

func MustFormInt64

func MustFormInt64(c echo.Context, key string, cbs ...CallbackFunc) int64

func MustFormString

func MustFormString(c echo.Context, key string, cbs ...CallbackFunc) string

func MustFormUint64

func MustFormUint64(c echo.Context, key string, cbs ...CallbackFunc) uint64

func MustHeaderBool

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

func MustHeaderInt64

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

func MustHeaderString

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

func MustHeaderUInt64

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

func MustJSONBindBody

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

func MustMsgpackBindBody

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

func MustParamBool

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

func MustParamInt64

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

func MustParamString

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

func MustParamUInt64

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

func MustPostFormBool

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

func MustPostFormInt64

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

func MustPostFormString

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

func MustPostFormUInt64

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

func MustProtobufBindBody

func MustProtobufBindBody(c echo.Context, v interface{}, cbs ...CallbackFunc)

func MustQueryBool

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

func MustQueryInt64

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

func MustQueryString

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

func MustQueryUInt64

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

func MustValidate

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

func MustXMLBindBody

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

func MustYAMLBindBody

func MustYAMLBindBody(c echo.Context, v interface{}, cbs ...CallbackFunc)

func New

func New(c echo.Context, v interface{}) *proxy

func NewDefaultEcho added in v1.0.3

func NewDefaultEcho() *echo.Echo

func NewDefaultLogger added in v1.0.1

func NewDefaultLogger() *zap.SugaredLogger

func Panic added in v1.0.2

func Panic(format string, args ...interface{})

Panic logs a message, then panics.

func PanicKV added in v1.0.3

func PanicKV(msg string, fields ...zap.Field)

PanicKV logs a message, then panics.

func ParamBool

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

func ParamInt64

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

func ParamString

func ParamString(c echo.Context, key string) (string, error)

func ParamUint64

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

func PostFormBool

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

func PostFormInt64

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

func PostFormString

func PostFormString(c echo.Context, key string) (string, error)

func PostFormUint64

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

func ProtobufBindBody

func ProtobufBindBody(c echo.Context, v interface{}) error

ProtobufBindBody needs tag "protobuf" in fields of v.

func QueryBool

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

func QueryInt64

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

func QueryString

func QueryString(c echo.Context, key string) (string, error)

func QueryUint64

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

func RegisterCode

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

RegisterCode will not cover code and status which exists.

func ReleaseBuffer

func ReleaseBuffer(buffer *bytes.Buffer)

func ReleaseEchotoolError

func ReleaseEchotoolError(e *EchotoolError)

func SetLogger added in v1.0.1

func SetLogger(l *zap.SugaredLogger)

func SetRequestID

func SetRequestID(f func(c echo.Context) string) echo.MiddlewareFunc

func Validate

func Validate(v interface{}) error

Validate needs tag "valid" in fields of v.

func Warn added in v1.0.2

func Warn(format string, args ...interface{})

func WarnKV added in v1.0.3

func WarnKV(msg string, fields ...zap.Field)

func XMLBindBody

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

XMLBindBody needs tag "xml" in fields of v.

func YAMLBindBody

func YAMLBindBody(c echo.Context, v interface{}) error

YAMLBindBody needs tag "yaml" in fields of v.

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 (ec *Context) Abort(code int, err error)

func (*Context) Finish

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

func (*Context) GetCode

func (ec *Context) GetCode() int

func (*Context) GetCustomValue added in v1.0.1

func (ec *Context) GetCustomValue(key string) (value string, exists bool)

func (*Context) GetCustomValues added in v1.0.1

func (ec *Context) GetCustomValues() map[string]string

func (*Context) GetData

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

func (*Context) GetError

func (ec *Context) GetError() error

func (*Context) GetNamedValue added in v1.0.1

func (ec *Context) GetNamedValue() string

func (*Context) IsOK

func (ec *Context) IsOK() bool

func (*Context) SetCustomValue added in v1.0.1

func (ec *Context) SetCustomValue(key, value string)

func (*Context) SetNamedValue added in v1.0.1

func (ec *Context) SetNamedValue(value string)

func (*Context) String

func (ec *Context) String() string

type EchotoolError

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

func AcquireEchotoolError

func AcquireEchotoolError(code int, err error) (e *EchotoolError)

func (EchotoolError) Error

func (e EchotoolError) Error() string

func (EchotoolError) GetCode

func (e EchotoolError) GetCode() int

func (EchotoolError) GetError

func (e EchotoolError) GetError() error

type EmptyError

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

func NewEmptyError

func NewEmptyError(kind Kind, key string) *EmptyError

func NewFormEmptyError

func NewFormEmptyError(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 NewDefaultEngine added in v1.0.3

func NewDefaultEngine(opts ...Option) *Engine

func NewEngine

func NewEngine(opts ...Option) *Engine

func (*Engine) EchoHandler

func (e *Engine) EchoHandler(handlers ...HandlerFunc) echo.HandlerFunc

func (*Engine) Use

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

type HandlerFunc

type HandlerFunc func(echo.Context, *Context)

func AddNotice added in v1.0.1

func AddNotice(key, value string) HandlerFunc

AddNotice adds kv pair to log for troubleshooting problems and so on.

func AddTraceID added in v1.0.1

func AddTraceID(f func(c echo.Context) string) HandlerFunc

AddTraceID adds trace id to log for troubleshooting problems and so on.

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
	KindForm
)

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)

Jump to

Keyboard shortcuts

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