Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateUUID() string
- func GetValidatorFieldError(err error) map[string]string
- func LoadConfiguration() (v *viper.Viper, err error)
- func ValidateStruct(req interface{}) error
- type BusinessCode
- type BusinessStatusCode
- type Causer
- type ErrorStage
- type ErrorType
- type ErrorWithCode
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 ( BusinessToError = map[ErrorType]BusinessCode{ ErrNotFound: NotFound, ErrForbidden: Forbidden, ErrBadRequest: BadRequest, ErrQueryRead: QueryReadInvalid, ErrQueryScan: QueryScanInvalid, ErrQueryTxBegin: QueryTxBeginInvalid, ErrQueryTxInsert: QueryTxInsertInvalid, ErrQueryTxUpdate: QueryTxUpdateInvalid, ErrQueryTxDelete: QueryTxDeleteInvalid, ErrQueryTxCommit: QueryTxCommitInvalid, ErrInvalidContentType: ContentTypeInvalid, } ErrorToBusiness = map[BusinessCode]ErrorType{ NotFound: ErrNotFound, Forbidden: ErrForbidden, BadRequest: ErrBadRequest, QueryReadInvalid: ErrQueryRead, QueryScanInvalid: ErrQueryScan, QueryTxBeginInvalid: ErrQueryTxBegin, QueryTxInsertInvalid: ErrQueryTxInsert, QueryTxUpdateInvalid: ErrQueryTxUpdate, QueryTxDeleteInvalid: ErrQueryTxDelete, QueryTxCommitInvalid: ErrQueryTxCommit, ContentTypeInvalid: ErrInvalidContentType, } )
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 GetValidatorFieldError ¶
func LoadConfiguration ¶ added in v0.0.3
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 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 )
type BusinessStatusCode ¶ added in v0.0.2
func GetStatusMessage ¶ added in v0.0.2
func GetStatusMessage(code BusinessCode) BusinessStatusCode
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
Click to show internal directories.
Click to hide internal directories.