utils

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// default values by convention
	DefaultType     = "json"
	DefaultFilename = "config"
	// environment variable key names
	EnvConsulHostKey = "GOCONF_CONSUL"
	EnvTypeKey       = "GOCONF_TYPE"
	EnvFileNameKey   = "GOCONF_FILENAME"
	EnvPrefixKey     = "GOCONF_ENV_PREFIX"
)

Variables

View Source
var BusinessStatusMessage = map[BusinessCode]BusinessStatusCode{
	Success:              {Message: "request success", HttpStatusCode: http.StatusOK},
	SuccessCreated:       {Message: "created success", HttpStatusCode: http.StatusCreated},
	SuccessNoContent:     {Message: "success with no content", HttpStatusCode: http.StatusNoContent},
	BadRequest:           {Message: "bad request", HttpStatusCode: http.StatusBadRequest},
	Unauthorized:         {Message: "unauthorized", HttpStatusCode: http.StatusUnauthorized},
	Forbidden:            {Message: "forbidden", HttpStatusCode: http.StatusForbidden},
	NotFound:             {Message: "data not found", HttpStatusCode: http.StatusNotFound},
	MethodNotAllowed:     {Message: "request not allowed", HttpStatusCode: http.StatusMethodNotAllowed},
	RequestTimeout:       {Message: "request time out", HttpStatusCode: http.StatusRequestTimeout},
	TooManyRequests:      {Message: "to many request", HttpStatusCode: http.StatusTooManyRequests},
	QueryReadInvalid:     {Message: "error while querying storage", HttpStatusCode: http.StatusInternalServerError},
	QueryScanInvalid:     {Message: "error when scan query result", HttpStatusCode: http.StatusInternalServerError},
	QueryTxBeginInvalid:  {Message: "error while preparing query transaction", HttpStatusCode: http.StatusInternalServerError},
	QueryTxInsertInvalid: {Message: "error while inserting record", HttpStatusCode: http.StatusInternalServerError},
	QueryTxUpdateInvalid: {Message: "error while updating record", HttpStatusCode: http.StatusInternalServerError},
	QueryTxDeleteInvalid: {Message: "error while deleting record", HttpStatusCode: http.StatusInternalServerError},
	QueryTxCommitInvalid: {Message: "error while committing record changes", HttpStatusCode: http.StatusInternalServerError},
	ContentTypeInvalid:   {Message: "invalid content type", HttpStatusCode: http.StatusInternalServerError},
	Undefine:             {Message: "something went wrong", HttpStatusCode: http.StatusInternalServerError},
	InternalError:        {Message: "internal server error", HttpStatusCode: http.StatusInternalServerError},
	BadGateway:           {Message: "bad gateway", HttpStatusCode: http.StatusBadGateway},
	ServiceUnavailable:   {Message: "service unavailable", HttpStatusCode: http.StatusServiceUnavailable},
}

Functions

func GenerateUUID

func GenerateUUID() string

GenerateUUID to generate random uuid.

func GetValidatorFieldError

func GetValidatorFieldError(err error) map[string]string

func LoadConfiguration added in v0.0.3

func LoadConfiguration() (v *viper.Viper, err error)

func ValidateStruct

func ValidateStruct(req interface{}) error

Types

type BusinessCode added in v0.0.2

type BusinessCode int
const (
	Success              BusinessCode = 200
	SuccessCreated       BusinessCode = 201
	SuccessNoContent     BusinessCode = 204
	BadRequest           BusinessCode = 400
	Unauthorized         BusinessCode = 401
	Forbidden            BusinessCode = 403
	NotFound             BusinessCode = 404
	MethodNotAllowed     BusinessCode = 405
	RequestTimeout       BusinessCode = 408
	TooManyRequests      BusinessCode = 429
	QueryReadInvalid     BusinessCode = 460
	QueryScanInvalid     BusinessCode = 461
	QueryTxBeginInvalid  BusinessCode = 462
	QueryTxInsertInvalid BusinessCode = 463
	QueryTxUpdateInvalid BusinessCode = 464
	QueryTxDeleteInvalid BusinessCode = 465
	QueryTxCommitInvalid BusinessCode = 466
	ContentTypeInvalid   BusinessCode = 467
	Undefine             BusinessCode = 499
	InternalError        BusinessCode = 500
	BadGateway           BusinessCode = 502
	ServiceUnavailable   BusinessCode = 503
)

type BusinessStatusCode added in v0.0.2

type BusinessStatusCode struct {
	Message        string
	HttpStatusCode int
}

func GetStatusMessage added in v0.0.2

func GetStatusMessage(code BusinessCode) BusinessStatusCode

type Causer

type Causer interface {
	Cause() error
}

type ErrorStage

type ErrorStage string
var (
	ERROR_REPOSITORY_STAGE ErrorStage = "repository"
	ERROR_USE_CASE_STAGE   ErrorStage = "use-case"
	ERROR_HANDLER_STAGE    ErrorStage = "handler"
	ERROR_INFRA_STAGE      ErrorStage = "infra"
)

type ErrorType

type ErrorType error
var (
	ErrNotFound           ErrorType = errors.New("data not found")
	ErrForbidden          ErrorType = errors.New("forbidden access")
	ErrBadRequest         ErrorType = errors.New("bad request")
	ErrQueryRead          ErrorType = errors.New("error while querying storage")
	ErrQueryScan          ErrorType = errors.New("error while scan query result")
	ErrQueryTxBegin       ErrorType = errors.New("error while preparing query transaction")
	ErrQueryTxInsert      ErrorType = errors.New("error while inserting record")
	ErrQueryTxUpdate      ErrorType = errors.New("error while updating record")
	ErrQueryTxDelete      ErrorType = errors.New("error while deleting record")
	ErrQueryTxCommit      ErrorType = errors.New("error while committing record changes")
	ErrInvalidContentType ErrorType = errors.New("invalid content type")
)

type ErrorWithCode

type ErrorWithCode struct {
	// contains filtered or unexported fields
}

func NewErrorWithCode

func NewErrorWithCode(c int, e error) *ErrorWithCode

func (*ErrorWithCode) Cause

func (err *ErrorWithCode) Cause() error

func (*ErrorWithCode) Code

func (err *ErrorWithCode) Code() int

func (*ErrorWithCode) Error

func (err *ErrorWithCode) Error() string

Jump to

Keyboard shortcuts

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