Documentation ¶
Overview ¶
Package pkg is a generated GoMock package.
Package pkg is a generated GoMock package.
Index ¶
- Variables
- func CamelToSnakeCase(str string) string
- func CheckMetadataKeyAndValueLength(limit int, metadata map[string]any) error
- func Contains[T comparable](slice []T, item T) bool
- func ContextWithLogger(ctx context.Context, logger mlog.Logger) context.Context
- func ContextWithMidazID(ctx context.Context, midazID string) context.Context
- func ContextWithTracer(ctx context.Context, tracer trace.Tracer) context.Context
- func EnsureConfigFromEnvVars(s any) any
- func GenerateUUIDv7() uuid.UUID
- func GetCPUUsage(ctx context.Context, exc SyscmdI) int64
- func GetMapNumKinds() map[reflect.Kind]bool
- func GetMemUsage(ctx context.Context, exc SyscmdI) int64
- func GetenvBoolOrDefault(key string, defaultValue bool) bool
- func GetenvIntOrDefault(key string, defaultValue int64) int64
- func GetenvOrDefault(key string, defaultValue string) string
- func HashSHA256(input string) string
- func IsDateRangeWithinMonthLimit(initial, final time.Time, limit int) bool
- func IsInitialDateBeforeFinalDate(initial, final time.Time) bool
- func IsNilOrEmpty(s *string) bool
- func IsUUID(s string) bool
- func IsValidDate(date string) bool
- func MergeMaps(source, target map[string]any) map[string]any
- func NewLoggerFromContext(ctx context.Context) mlog.Logger
- func NewMidazIDFromContext(ctx context.Context) string
- func NewTracerFromContext(ctx context.Context) trace.Tracer
- func NormalizeDate(date time.Time, days *int) string
- func RegexIgnoreAccents(regex string) string
- func RemoveAccents(word string) (string, error)
- func RemoveChars(str string, chars map[string]bool) string
- func RemoveSpaces(word string) string
- func ReplaceUUIDWithPlaceholder(path string) string
- func Reverse[T any](s []T) []T
- func SafeInt64ToInt(val int64) int
- func SafeIntToUint64(val int) uint64
- func SetConfigFromEnvVars(s any) error
- func StructToJSONString(s any) (string, error)
- func ValidateAccountType(t string) error
- func ValidateBadRequestFieldsError(requiredFields, knownInvalidFields map[string]string, entityType string, ...) error
- func ValidateBusinessError(err error, entityType string, args ...any) error
- func ValidateCode(code string) error
- func ValidateCountryAddress(country string) error
- func ValidateCurrency(code string) error
- func ValidateInternalError(err error, entityType string) error
- func ValidateServerAddress(value string) string
- func ValidateType(t string) error
- type App
- type CustomContextKeyValue
- type EntityConflictError
- type EntityNotFoundError
- type FailedPreconditionError
- type FieldValidations
- type ForbiddenError
- type HTTPError
- type InternalServerError
- type Launcher
- type LauncherOption
- type LocalEnvConfig
- type MockApp
- type MockAppMockRecorder
- type MockSyscmdI
- type MockSyscmdIMockRecorder
- type ResponseError
- type Syscmd
- type SyscmdI
- type UnauthorizedError
- type UnknownFields
- type UnprocessableOperationError
- type ValidationError
- type ValidationKnownFieldsError
- type ValidationUnknownFieldsError
Constants ¶
This section is empty.
Variables ¶
var CustomContextKey = customContextKey("custom_context")
Functions ¶
func CamelToSnakeCase ¶
CamelToSnakeCase converts a given camelCase string to snake_case format.
func CheckMetadataKeyAndValueLength ¶
CheckMetadataKeyAndValueLength check the length of key and value to a limit pass by on field limit
func Contains ¶
func Contains[T comparable](slice []T, item T) bool
Contains checks if an item is in a slice. This function uses type parameters to work with any slice type.
func ContextWithLogger ¶
ContextWithLogger returns a context within a Logger in "logger" value.
func ContextWithMidazID ¶
ContextWithMidazID returns a context within a MidazID in "midazID" value.
func ContextWithTracer ¶
ContextWithTracer returns a context within a trace.Tracer in "tracer" value.
func EnsureConfigFromEnvVars ¶
EnsureConfigFromEnvVars ensures that an interface will be settled using SetConfigFromEnvVars anyway.
func GenerateUUIDv7 ¶
GenerateUUIDv7 generate a new uuid v7 using google/uuid package and return it. If an error occurs, it will return the error.
func GetCPUUsage ¶
GetCPUUsage get the current CPU usage
func GetMapNumKinds ¶
GetMapNumKinds get the map of numeric kinds to use in validations and conversions.
The numeric kinds are: - int - int8 - int16 - int32 - int64 - float32 - float64
func GetMemUsage ¶
GetMemUsage get the current memory usage
func GetenvBoolOrDefault ¶
GetenvBoolOrDefault returns the value of os.Getenv(key string) value as bool or defaultValue if error Is the environment variable (key) is not defined, it returns the given defaultValue If the environment variable (key) is not a valid bool format, it returns the given defaultValue If any error occurring during bool parse, it returns the given defaultValue.
func GetenvIntOrDefault ¶
GetenvIntOrDefault returns the value of os.Getenv(key string) value as int or defaultValue if error If the environment variable (key) is not defined, it returns the given defaultValue If the environment variable (key) is not a valid int format, it returns the given defaultValue If any error occurring during int parse, it returns the given defaultValue.
func GetenvOrDefault ¶
GetenvOrDefault encapsulate built-in os.Getenv behavior but if key is not present it returns the defaultValue.
func HashSHA256 ¶ added in v1.34.0
HashSHA256 generate a hash sha-256 to create idempotency on redis
func IsDateRangeWithinMonthLimit ¶ added in v1.31.0
IsDateRangeWithinMonthLimit checks if the date range is within the permitted range in months.
func IsInitialDateBeforeFinalDate ¶ added in v1.31.0
IsInitialDateBeforeFinalDate checks if the initial date is before or equal to the final date.
func IsNilOrEmpty ¶
IsNilOrEmpty returns a boolean indicating if a *string is nil or empty. It's use TrimSpace so, a string " " and "" and "null" and "nil" will be considered empty
func IsValidDate ¶ added in v1.31.0
IsValidDate checks if the provided date string is in the format "YYYY-MM-DD".
func NewLoggerFromContext ¶
NewLoggerFromContext extract the Logger from "logger" value inside context
func NewMidazIDFromContext ¶
NewMidazIDFromContext returns a MidazID from the context.
func NewTracerFromContext ¶
NewTracerFromContext returns a new tracer from the context.
func NormalizeDate ¶ added in v1.31.0
NormalizeDate normalizes a date adding or subtracting days to make it match the query requirements and string format.
func RegexIgnoreAccents ¶
RegexIgnoreAccents receives a regex, then, for each char it's adds the accents variations to expression Ex: Given "a" -> "aáàãâ" Ex: Given "c" -> "ç"
func RemoveAccents ¶
RemoveAccents removes accents of a given word and returns it
func RemoveChars ¶
RemoveChars from a string
func RemoveSpaces ¶
RemoveSpaces removes spaces of a given word and returns it
func ReplaceUUIDWithPlaceholder ¶
ReplaceUUIDWithPlaceholder replaces UUIDs with a placeholder in a given path string.
func Reverse ¶ added in v1.31.0
func Reverse[T any](s []T) []T
Reverse reverses a slice of any type.
func SafeInt64ToInt ¶ added in v1.31.0
SafeInt64ToInt safely converts int64 to int
func SafeIntToUint64 ¶
SafeIntToUint64 safe mode to converter int to uint64
func SetConfigFromEnvVars ¶
SetConfigFromEnvVars builds a struct by setting it fields values using the "var" tag Constraints: s any - must be an initialized pointer Supported types: String, Boolean, Int, Int8, Int16, Int32 and Int64.
func StructToJSONString ¶
StructToJSONString convert a struct to json string
func ValidateAccountType ¶
ValidateAccountType validate type values of accounts
func ValidateBadRequestFieldsError ¶
func ValidateBadRequestFieldsError(requiredFields, knownInvalidFields map[string]string, entityType string, unknownFields map[string]any) error
ValidateBadRequestFieldsError validates the error and returns the appropriate bad request error code, title, message, and the invalid fields.
Parameters: - requiredFields: A map of missing required fields and their error messages. - knownInvalidFields: A map of known invalid fields and their validation errors. - entityType: The type of the entity associated with the error. - unknownFields: A map of unknown fields and their error messages.
Returns: - An error indicating the validation result, which could be a ValidationUnknownFieldsError or a ValidationKnownFieldsError.
func ValidateBusinessError ¶
ValidateBusinessError validates the error and returns the appropriate business error code, title, and message.
Parameters:
- err: The error to be validated (ref: https://github.com/LerianStudio/midaz/common/constant/errors.go).
- entityType: The type of the entity related to the error.
- args: Additional arguments for formatting error messages.
Returns:
- error: The appropriate business error with code, title, and message.
func ValidateCode ¶
func ValidateCountryAddress ¶
ValidateCountryAddress validate if country in object address contains in countries list using ISO 3166-1 alpha-2
func ValidateCurrency ¶
ValidateCurrency validate if code contains in currencies list using ISO 4217
func ValidateInternalError ¶
ValidateInternalError validates the error and returns an appropriate InternalServerError.
Parameters: - err: The error to be validated. - entityType: The type of the entity associated with the error.
Returns: - An InternalServerError with the appropriate code, title, message.
func ValidateServerAddress ¶ added in v1.30.0
ValidateServerAddress checks if the value matches the pattern <some-address>:<some-port> and returns the value if it does.
func ValidateType ¶
ValidateType validate type values of currencies
Types ¶
type App ¶
App represents an application that will run as a deployable component. It's an entrypoint at main.go.
type CustomContextKeyValue ¶
type EntityConflictError ¶
type EntityConflictError struct { EntityType string Title string Message string Code string Err error }
EntityConflictError records an error indicating an entity already exists in some repository You can use it to representing a Database conflict, cache or any other repository.
func (EntityConflictError) Error ¶
func (e EntityConflictError) Error() string
Error implements the error interface.
func (EntityConflictError) Unwrap ¶
func (e EntityConflictError) Unwrap() error
Unwrap implements the error interface introduced in Go 1.13 to unwrap the internal error.
type EntityNotFoundError ¶
type EntityNotFoundError struct { EntityType string Title string Message string Code string Err error }
EntityNotFoundError records an error indicating an entity was not found in any case that caused it. You can use it to representing a Database not found, cache not found or any other repository.
func (EntityNotFoundError) Error ¶
func (e EntityNotFoundError) Error() string
Error implements the error interface.
func (EntityNotFoundError) Unwrap ¶
func (e EntityNotFoundError) Unwrap() error
Unwrap implements the error interface introduced in Go 1.13 to unwrap the internal error.
type FailedPreconditionError ¶
type FailedPreconditionError struct { EntityType string `json:"entityType,omitempty"` Title string `json:"title,omitempty"` Message string `json:"message,omitempty"` Code string `json:"code,omitempty"` Err error `json:"err,omitempty"` }
FailedPreconditionError indicates a precondition failed during an operation.
func (FailedPreconditionError) Error ¶
func (e FailedPreconditionError) Error() string
type FieldValidations ¶
FieldValidations is a map of known fields and their validation errors.
type ForbiddenError ¶
type ForbiddenError struct { EntityType string `json:"entityType,omitempty"` Title string `json:"title,omitempty"` Message string `json:"message,omitempty"` Code string `json:"code,omitempty"` Err error `json:"err,omitempty"` }
ForbiddenError indicates an operation that couldn't be performant because the authenticated user has no sufficient privileges.
func (ForbiddenError) Error ¶
func (e ForbiddenError) Error() string
type InternalServerError ¶
type InternalServerError struct { EntityType string `json:"entityType,omitempty"` Title string `json:"title,omitempty"` Message string `json:"message,omitempty"` Code string `json:"code,omitempty"` Err error `json:"err,omitempty"` }
InternalServerError indicates a precondition failed during an operation.
func (InternalServerError) Error ¶
func (e InternalServerError) Error() string
type Launcher ¶
Launcher manages apps.
func NewLauncher ¶
func NewLauncher(opts ...LauncherOption) *Launcher
NewLauncher create an instance of Launch.
type LauncherOption ¶
type LauncherOption func(l *Launcher)
LauncherOption defines a function option for Launcher.
func RunApp ¶
func RunApp(name string, app App) LauncherOption
RunApp start all process registered before to the launcher.
func WithLogger ¶
func WithLogger(logger mlog.Logger) LauncherOption
WithLogger adds a mlog.Logger component to launcher.
type LocalEnvConfig ¶
type LocalEnvConfig struct {
Initialized bool
}
LocalEnvConfig is used to automatically call the InitLocalEnvConfig method using Dependency Injection So, if a func parameter or a struct field depends on LocalEnvConfig, when DI starts, it will call InitLocalEnvConfig as the LocalEnvConfig provider.
func InitLocalEnvConfig ¶
func InitLocalEnvConfig() *LocalEnvConfig
InitLocalEnvConfig load a .env file to set up local environment vars It's called once per application process.
type MockApp ¶ added in v1.31.0
type MockApp struct {
// contains filtered or unexported fields
}
MockApp is a mock of App interface.
func NewMockApp ¶ added in v1.31.0
func NewMockApp(ctrl *gomock.Controller) *MockApp
NewMockApp creates a new mock instance.
func (*MockApp) EXPECT ¶ added in v1.31.0
func (m *MockApp) EXPECT() *MockAppMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockAppMockRecorder ¶ added in v1.31.0
type MockAppMockRecorder struct {
// contains filtered or unexported fields
}
MockAppMockRecorder is the mock recorder for MockApp.
type MockSyscmdI ¶ added in v1.31.0
type MockSyscmdI struct {
// contains filtered or unexported fields
}
MockSyscmdI is a mock of SyscmdI interface.
func NewMockSyscmdI ¶ added in v1.31.0
func NewMockSyscmdI(ctrl *gomock.Controller) *MockSyscmdI
NewMockSyscmdI creates a new mock instance.
func (*MockSyscmdI) EXPECT ¶ added in v1.31.0
func (m *MockSyscmdI) EXPECT() *MockSyscmdIMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockSyscmdIMockRecorder ¶ added in v1.31.0
type MockSyscmdIMockRecorder struct {
// contains filtered or unexported fields
}
MockSyscmdIMockRecorder is the mock recorder for MockSyscmdI.
type ResponseError ¶
type ResponseError struct { Code int `json:"code,omitempty"` Title string `json:"title,omitempty"` Message string `json:"message,omitempty"` }
ResponseError is a struct used to return errors to the client.
func (ResponseError) Error ¶
func (r ResponseError) Error() string
Error returns the message of the ResponseError.
No parameters. Returns a string.
type UnauthorizedError ¶
type UnauthorizedError struct {}
UnauthorizedError indicates an operation that couldn't be performant because there's no user authenticated.
func (UnauthorizedError) Error ¶
func (e UnauthorizedError) Error() string
type UnknownFields ¶
UnknownFields is a map of unknown fields and their error messages.
type UnprocessableOperationError ¶
type UnprocessableOperationError struct { EntityType string Title string Message string Code string Err error }
UnprocessableOperationError indicates an operation that couldn't be performant because it's invalid.
func (UnprocessableOperationError) Error ¶
func (e UnprocessableOperationError) Error() string
type ValidationError ¶
type ValidationError struct { EntityType string `json:"entityType,omitempty"` Title string Message string Code string Err error `json:"err,omitempty"` }
ValidationError records an error indicating an entity was not found in any case that caused it. You can use it to representing a Database not found, cache not found or any other repository.
func (ValidationError) Error ¶
func (e ValidationError) Error() string
Error implements the error interface.
func (ValidationError) Unwrap ¶
func (e ValidationError) Unwrap() error
Unwrap implements the error interface introduced in Go 1.13 to unwrap the internal error.
type ValidationKnownFieldsError ¶
type ValidationKnownFieldsError struct { EntityType string `json:"entityType,omitempty"` Title string `json:"title,omitempty"` Code string `json:"code,omitempty"` Message string `json:"message,omitempty"` Fields FieldValidations `json:"fields,omitempty"` }
ValidationKnownFieldsError records an error that occurred during a validation of known fields.
func (ValidationKnownFieldsError) Error ¶
func (r ValidationKnownFieldsError) Error() string
Error returns the error message for a ValidationKnownFieldsError.
No parameters. Returns a string.
type ValidationUnknownFieldsError ¶
type ValidationUnknownFieldsError struct { EntityType string `json:"entityType,omitempty"` Title string `json:"title,omitempty"` Code string `json:"code,omitempty"` Message string `json:"message,omitempty"` Fields UnknownFields `json:"fields,omitempty"` }
ValidationUnknownFieldsError records an error that occurred during a validation of known fields.
func (ValidationUnknownFieldsError) Error ¶
func (r ValidationUnknownFieldsError) Error() string
Error returns the error message for a ValidationUnknownFieldsError.
No parameters. Returns a string.