rest

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeUnknown        = -1
	CodeSuccess        = 0
	CodeBindJsonFailed = 1
	CodePreCheckFailed = 2
)

Variables

View Source
var ErrFunc func(err error)

Functions

func Failed added in v1.2.0

func Failed(c *gin.Context, err error)

func GenericReq added in v1.2.0

func GenericReq[T any](context *gin.Context, handler func(receive T) (interface{}, error))

func RegisterHandler added in v1.2.2

func RegisterHandler(engine gin.IRouter, rootPath string, handler Handler)

func Response

func Response(c *gin.Context, result Result)

func SimpleReq added in v1.2.0

func SimpleReq(context *gin.Context, handler func() (interface{}, error))

func Success added in v1.2.0

func Success(c *gin.Context, data interface{})

Types

type Check

type Check interface {
	Check() (bool, string)
}

type Handler added in v1.2.2

type Handler interface {
	Routes() []Route
}

type HttpError

type HttpError struct {
	Err        error `json:"-"`
	Code       int   `json:"code"`
	HttpStatus int   `json:"-"`
}

func CodeError

func CodeError(err error, code int) HttpError

func NewHttpError

func NewHttpError(err error, code int, httpStatus int) HttpError

func StatusError

func StatusError(err error, httpStatus int) HttpError

func (HttpError) Error

func (e HttpError) Error() string

type Result

type Result struct {
	Err        error       `json:"-"`
	Code       int         `json:"code"`
	HttpStatus int         `json:"-"`
	Data       interface{} `json:"data,omitempty"`
	Message    string      `json:"message,omitempty"`
}

func NewResult

func NewResult(code int, data interface{}, err error, status int) Result

type Route added in v1.2.2

type Route struct {
	Method  string
	Path    string
	Handler func(context *gin.Context)
}

type Router added in v1.2.2

type Router struct {
	RootPath string
	Routes   []Route
}

func (Router) RegisterHandler added in v1.2.2

func (router Router) RegisterHandler(engine gin.IRouter)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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