util

package
v0.0.0-...-f2be101 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Success status
	Success codes.Code = 200
	//SuccessCreated status
	SuccessCreated codes.Code = 201
	// SuccessNoContent status
	SuccessNoContent codes.Code = 204
	// InvalidArgument status
	InvalidArgument codes.Code = 400
	// Unauthorized status
	Unauthorized codes.Code = 401
	// Forbidden status
	Forbidden codes.Code = 403
	// NotFound status
	NotFound codes.Code = 404
	// Cancelled status
	Cancelled codes.Code = 405
	// RequestTimeout status
	RequestTimeout codes.Code = 408

	// InactiveAccount status
	InactiveAccount codes.Code = 410
	// InvalidToken status
	InvalidToken codes.Code = 411
	// InvalidAPIKey status
	InvalidAPIKey codes.Code = 412
	// InvalidSession status
	InvalidSession codes.Code = 413
	// ResourceExhausted status
	ResourceExhausted codes.Code = 414

	// InvalidSubdomain status
	InvalidSubdomain codes.Code = 420
	// InactiveSubdomain status
	InactiveSubdomain codes.Code = 421
	// SuspendedSubdomain status
	SuspendedSubdomain codes.Code = 422

	// InvalidTransaction status
	InvalidTransaction codes.Code = 430
	// DuplicateTransaction status
	DuplicateTransaction codes.Code = 431

	// InternalError status
	InternalError codes.Code = 500
	// ProcessingError status
	ProcessingError codes.Code = 502
)

Variables

Functions

func CustomErrorHandler

func CustomErrorHandler(c *echo.Echo)

func HTTPStatusFromCode

func HTTPStatusFromCode(c codes.Code) int

HTTPStatusFromCode return HTTP Status for each code

func StringToInt

func StringToInt(s string) int

Types

type CustomValidator

type CustomValidator struct {
	Validator *validator.Validate
}

CustomValidator validation that handle validation

func (*CustomValidator) Validate

func (cv *CustomValidator) Validate(i interface{}) error

Validate struct

type Pagination

type Pagination struct {
	CurrentPage int32 `json:"current_page"`
	PageSize    int32 `json:"page_size"`
	TotalPage   int32 `json:"total_page"`
	TotalResult int32 `json:"total_result"`
}

func NewPagination

func NewPagination(page int32, count int32) *Pagination

NewPagination initiate new pagination obj

func (*Pagination) Limit

func (p *Pagination) Limit() int32

Limit get limit

func (*Pagination) LimitOffset

func (p *Pagination) LimitOffset() string

LimitOffset generate limit and offset for pagination

func (*Pagination) Offset

func (p *Pagination) Offset() int32

Offset get Offset

func (*Pagination) SetTotalPage

func (p *Pagination) SetTotalPage(total int32) *Pagination

SetTotalPage calculate total page by total count data

type Response

type Response struct {
	Code       grpcCode.Code          `json:"code"`
	Message    string                 `json:"message,omitempty"`
	Data       interface{}            `json:"data,omitempty"`
	Pagination *Pagination            `json:"pagination,omitempty"`
	Errors     []string               `json:"errors,omitempty"`
	Header     map[string]interface{} `json:"-"`
}

Response struct

func (*Response) JSON

func (r *Response) JSON(c echo.Context) error

JSON render response as JSON

func (*Response) WithPagination

func (r *Response) WithPagination(c echo.Context, pagination *Pagination) *Response

WithPagination set response with pagination

Jump to

Keyboard shortcuts

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