context

package
v0.0.0-...-e2dd9e7 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2022 License: Unlicense Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LangUS = "en-US"
	LangBR = "pt-BR"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	LoggedAuth domains.Auth
	CID        string `json:"cid"`
	HTTPPrefix string
	Logger     *log.Entry
	Version    string
	Localizer  *i18n.Localizer
	Lang       LangType
	HostURL    string `json:"host_url"`
}

Context .

func New

func New() *Context

New create a new context instance

func (*Context) ResultError

func (c *Context) ResultError(errorCode int, description string, params ...interface{}) Result

ResultError build a common struct for validation error result.

func (*Context) ResultNotFound

func (c *Context) ResultNotFound(errorCode int, description string, params ...interface{}) Result

ResultNotFound when any record was not found

func (*Context) ResultSuccess

func (c *Context) ResultSuccess() Result

ResultSuccess build a common struct for success.

func (*Context) ResultUnauthorized

func (c *Context) ResultUnauthorized() Result

ResultUnauthorized Unauthorized

func (*Context) Unexpected

func (c *Context) Unexpected(err error, data ...interface{}) Result

Unexpected build a struct for unexpected error result.

func (*Context) WithLogger

func (c *Context) WithLogger() *Context

WithLogger add logger to context.

type LangType

type LangType string

type Result

type Result struct {
	State            ResultState
	Error            error
	ErrorCode        int
	ErrorDescription string
}

Result is a struct of result.

func (Result) JSON

func (r Result) JSON(c *gin.Context, body interface{})

JSON convert Result to HTTP Response.

type ResultError

type ResultError struct {
	Code        int    `json:"error_code"`
	Description string `json:"error_description"`
}

ResultError base struct for application errors.

type ResultState

type ResultState int

ResultState represent actual state of result.

const (
	// ResultStateSuccess state is when the result is ok.
	ResultStateSuccess ResultState = 0

	// ResultStateError state is when the result has validation error.
	ResultStateError ResultState = 1

	// ResultStateUnexpected state is when the result has unexpected error.
	ResultStateUnexpected ResultState = 2

	// ResultStateNotFound when a register was not found
	ResultStateNotFound ResultState = 3

	// ResultStateUnauthorized unauthorized
	ResultStateUnauthorized ResultState = 4
)

Jump to

Keyboard shortcuts

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