api

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 10 Imported by: 6

Documentation

Index

Constants

View Source
const (
	ErrCodeSuccess         = 0
	ErrCodeValidation      = 1
	ErrCodeInternal        = 2
	ErrCodeTooManyRequests = 3
)

Variables

This section is empty.

Functions

func MustServe

func MustServe(config Config, factory RouteFactory, mws ...middlewares.Middleware)

func MustServeFromViper

func MustServeFromViper(factory RouteFactory, middlewares ...middlewares.Middleware)

func ResponseCsv

func ResponseCsv(c *gin.Context, filename string, content [][]string)

func ResponseError

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

func ResponseSuccess

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

func Wrap

func Wrap(controller func(c *gin.Context) (interface{}, error)) gin.HandlerFunc

Types

type BusinessError

type BusinessError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

func ErrInternal

func ErrInternal(err error) *BusinessError

func ErrTooManyRequests

func ErrTooManyRequests(err error) *BusinessError

func ErrValidation

func ErrValidation(err error) *BusinessError

func NewBusinessError

func NewBusinessError(code int, message string, data interface{}) *BusinessError

func Success

func Success(data interface{}) *BusinessError

func (*BusinessError) Error

func (err *BusinessError) Error() string

type Config

type Config struct {
	Endpoint string `default:":12345"`

	RecoveryDisabled bool
	CorsOrigins      []string
	Logger           bool
}

type RouteFactory

type RouteFactory func(router *gin.Engine)

Jump to

Keyboard shortcuts

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