web

package
v0.0.0-...-09ba4a8 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReqBodyKey = prefix + "/req-body"
	ResBodyKey = prefix + "/res-body"
)

Variables

View Source
var (
	ErrInvalidToken    = NewResponse(9999, 401, "invalid signature")
	ErrNoPerm          = NewResponse(0, 401, "no permission")
	ErrNotFound        = NewResponse(0, 404, "not found")
	ErrMethodNotAllow  = NewResponse(0, 405, "method not allowed")
	ErrTooManyRequests = NewResponse(0, 429, "too many requests")
	ErrInternalServer  = NewResponse(0, 500, "internal server error")
	ErrBadRequest      = New400Response("bad request")
	ErrInvalidParent   = New400Response("not found parent node")
	ErrUserDisable     = New400Response("user forbidden")
)

Functions

func InitGinEngine

func InitGinEngine() *gin.Engine

func New400Response

func New400Response(msg string, args ...interface{}) error

func New500Response

func New500Response(msg string, args ...interface{}) error

func NewResponse

func NewResponse(code, status int, msg string, args ...interface{}) error

func NoMethodHandler

func NoMethodHandler() gin.HandlerFunc

func NoRouteHandler

func NoRouteHandler() gin.HandlerFunc

func ParseForm

func ParseForm(c *gin.Context, obj interface{}) error

ParseForm data to struct

func ParseHeader

func ParseHeader(c *gin.Context, obj interface{}) error

func ParseJSON

func ParseJSON(c *gin.Context, obj interface{}) error

ParseJSON data to struct

func ParseParamID

func ParseParamID(c *gin.Context, key string) int

ParseParamID returns the value of the URL param

func ParseQuery

func ParseQuery(c *gin.Context, obj interface{}) error

ParseQuery parameter to struct

func ParseUri

func ParseUri(c *gin.Context, obj interface{}) error

func ResError

func ResError(c *gin.Context, err error, status ...int)

ResError object and parse error status code

func ResJSON

func ResJSON(c *gin.Context, status int, v interface{})

ResJSON data with status code

func ResSuccess

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

ResSuccess data object

func Wrap400Response

func Wrap400Response(err error, msg string, args ...interface{}) error

func Wrap500Response

func Wrap500Response(err error, msg string, args ...interface{}) error

func WrapResponse

func WrapResponse(err error, code, status int, msg string, args ...interface{}) error

Types

type APIException

type APIException struct {
	StatusCode int               `json:"-"`
	Code       int               `json:"code"`
	Msg        string            `json:"msg"`
	Data       map[string]string `json:"data"`
}

type APISuccessResp

type APISuccessResp struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

type ResponseError

type ResponseError struct {
	Code    int // error code
	Message string
	Status  int // http code
	Err     error
}

func UnWrapResponse

func UnWrapResponse(err error) *ResponseError

func (*ResponseError) Error

func (r *ResponseError) Error() string

Jump to

Keyboard shortcuts

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