resp

package module
v0.0.0-...-37b9b94 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyRequestId = "_RequestId"
	KeyUserId    = "_UserId"
	KeyUserRole  = "UserRole"
	KEY_User     = "User"
	KeyError     = "error"
	KeyEvent     = "event"
)

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(ctx *gin.Context, cause error, msgs ...string)

func Error

func Error(ctx *gin.Context, err *HttpError)

func JSON

func JSON(ctx *gin.Context, data any, err *HttpError)

func Log2Tsv

func Log2Tsv(fp string, w io.Writer, times ...time.Time) (err error)

func NewLogHandler

func NewLogHandler[T any](logger *wrap.Logger, name string) gin.HandlerFunc

func Ok

func Ok(ctx *gin.Context)

Types

type HttpError

type HttpError struct {
	Cause string `json:"cause"`

	HttpCode int    `json:"httpCode"`
	Code     int    `json:"code"`
	Msg      string `json:"msg"`
	// contains filtered or unexported fields
}

func ErrBadRequest

func ErrBadRequest(cause error, opts ...Option) (err *HttpError)

code ranges:

...=-100 has no right
-99=-1   invalid request
0        ok
1..=99   business error
100...   unexpected error

func ErrConflict

func ErrConflict(err error, msg string) (out *HttpError)

func ErrInvalidParameter

func ErrInvalidParameter(err error, msg string) (out *HttpError)

func ErrNotFound

func ErrNotFound(err error) (out *HttpError)

func ErrParseFailed

func ErrParseFailed(cause error) (err *HttpError)

func ErrServerError

func ErrServerError(cause error, opts ...Option) (err *HttpError)

func ErrUnauthorized

func ErrUnauthorized(err error, msg string) (out *HttpError)

func NewHttpError

func NewHttpError(cause error, httpCode, code int, opts ...Option) (err *HttpError)

func (*HttpError) GetCause

func (err *HttpError) GetCause() error

type Option

type Option func(*HttpError) bool

func Msg

func Msg(msg string) Option

func Skip

func Skip(skip int) Option

Jump to

Keyboard shortcuts

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