Documentation ¶
Index ¶
- Constants
- Variables
- func GetEnvWithLog(key string) (string, bool)
- func GetIntEnvWithLog(key string) (int, bool)
- func InsertErrorResponse(c echo.Context, err error) error
- func InternalServerError(ctx context.Context, err error) error
- func JSONValidate(c echo.Context, i interface{}) error
- func ListErrorResponse(c echo.Context, err error) error
- func LogError(ctx context.Context, err error, lvl string)
- func MongoDeleteErr(err error, result *mongo.DeleteResult) error
- func MongoDeleteOneError(ctx context.Context, err error, coll string, result *mongo.DeleteResult) error
- func MongoErrorResponse(err error, collection string) *echo.HTTPError
- func MongoFindOneError(ctx context.Context, err error, coll string) error
- func MongoInsertOneError(ctx context.Context, err error, coll string) error
- func MongoUpdateErr(err error, result *mongo.UpdateResult) error
- func MongoUpdateOneError(ctx context.Context, err error, coll string, result *mongo.UpdateResult) error
- func SetLogLevel(l string)
- func ToSnakeCase(str string) string
- type APIError
- func (a *APIError) Conflict(m string) *APIError
- func (a *APIError) Forbidden(m string) *APIError
- func (a *APIError) InternalServerError() *APIError
- func (a *APIError) Log(c echo.Context)
- func (a *APIError) LogNats()
- func (a *APIError) NotFound(m string) *APIError
- func (a *APIError) Unauthorized() *APIError
- type BaseError
- type JSONError
- type JSONValidator
- type MongoBase
- type MongoConflict
- type ResponseError
Constants ¶
const ( //ColorRed use string(ColorRed) ColorRed = "\033[31m" //ColorGreen use string(ColorGreen) ColorGreen = "\033[32m" //ColorYellow use string(ColorYellow) ColorYellow = "\033[33m" //ColorBlue use string(ColorBlue) ColorBlue = "\033[34m" //ColorPurple use string(ColorPurple) ColorPurple = "\033[35m" //ColorCyan use string(ColorCyan) ColorCyan = "\033[36m" //ColorWhite use string(ColorWhite) ColorWhite = "\033[37m" //ErrorWithColor is a red string "Error: " ErrorWithColor = string(ColorRed) + "Error: " + string(ColorWhite) //WarningWithColor is a yellow string "Warning: " WarningWithColor = string(ColorYellow) + "Warning: " + string(ColorWhite) //SuccessWithColor is a green string "Success: " SuccessWithColor = string(ColorGreen) + "Success: " + string(ColorWhite) )
Variables ¶
var ErrJSONBind = errors.New("json can't bind to the interface")
var ErrJSONValidate = errors.New("json is not valid")
var ErrMongoDelete = errors.New("no delete document")
var ErrMongoUpdate = errors.New("no updated document")
var InternalServerErrorMsg = echo.NewHTTPError(http.StatusInternalServerError, BaseError{Message: "internal_server_error"})
InternalServerErrorMsg is an error that handles internal server error response
var LogLevel = "debug"
LogLevel can be set by SetLogLevel. Default value is debug
Functions ¶
func GetEnvWithLog ¶ added in v0.1.1
GetEnvWithLog Validate .env Variables
func GetIntEnvWithLog ¶ added in v0.1.1
GetIntEnvWithLog Validate .env Variables
func InsertErrorResponse ¶ added in v0.1.10
func InternalServerError ¶ added in v0.1.1
InternalServerError with logs
func JSONValidate ¶
func JSONValidate(c echo.Context, i interface{}) error
JSONValidate validates a json bind in echo.Context. The interface i is used for validation. If the c.Bind(i) or the validation returns errors the function return an APIError.
func ListErrorResponse ¶ added in v0.1.10
func MongoDeleteErr ¶ added in v0.1.10
func MongoDeleteErr(err error, result *mongo.DeleteResult) error
func MongoDeleteOneError ¶ added in v0.1.1
func MongoDeleteOneError(ctx context.Context, err error, coll string, result *mongo.DeleteResult) error
MongoDeleteOneError handles error response and logging for collection.deleteOne() function.
func MongoErrorResponse ¶ added in v0.1.12
func MongoFindOneError ¶ added in v0.1.1
MongoFindOneError handles error response and logging for collection.findOne() function.
func MongoInsertOneError ¶ added in v0.1.1
MongoInsertOneError handles error response and logging for collection.insertOne() function.
func MongoUpdateErr ¶ added in v0.1.10
func MongoUpdateErr(err error, result *mongo.UpdateResult) error
func MongoUpdateOneError ¶ added in v0.1.1
func MongoUpdateOneError(ctx context.Context, err error, coll string, result *mongo.UpdateResult) error
MongoUpdateOneError handles error response and logging for collection.deleteOne() function.
func SetLogLevel ¶ added in v0.1.1
func SetLogLevel(l string)
SetLogLevel can be used for set LogLevel variable
func ToSnakeCase ¶ added in v1.0.1
Types ¶
type APIError ¶
APIError represents the return value of all database controllers in case of an error.
func NewAPIError ¶
NewAPIError catches there context of calling and creates an APIError contains this informations. File is set to the name of the file and Line to the line in file NewAPIError was called from.
func (*APIError) Conflict ¶
Conflict extend APIError for http status 409 Conflict and adds a message m that can response to client.
func (*APIError) Forbidden ¶
Forbidden extend APIError for http status Forbidden and adds a message m that can response to client.
func (*APIError) InternalServerError ¶
InternalServerError extend APIError for http status 500 Internal Server Error
func (*APIError) LogNats ¶ added in v0.1.1
func (a *APIError) LogNats()
LogNats print APIError to server logs
func (*APIError) NotFound ¶
NotFound extend APIError for http status 404 Not Found and adds a message m that can response to client.
func (*APIError) Unauthorized ¶
Unauthorized extend APIError for http status 401 Unauthorized and adds a message m that can response to client.
type JSONError ¶
type JSONError struct {
Error []string `json:"error"`
}
JSONError represents a json validation error. Used om return of JSONErrorResponse:w
func JSONErrorResponse ¶
JSONErrorResponse creates a response for json validation error.
type JSONValidator ¶
JSONValidator validation struct using for JSON
func (*JSONValidator) Validate ¶
func (cv *JSONValidator) Validate(i interface{}) error
Validate extend JSONValidator with Validate function.
type MongoBase ¶ added in v0.1.1
MongoBase represents response type basic mongo error with collection involved.
type MongoConflict ¶ added in v0.1.1
type MongoConflict struct { Message string `json:"message"` Coll string `json:"collection"` Value string `json:"value"` }
MongoConflict represents the reponse type for mongo database Conficts.
type ResponseError ¶
type ResponseError struct { Message string `json:"message"` Data map[string]interface{} `json:"data,omitempty"` }
ResponseError represents the json body of an error response.