common

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelToSnakeCase

func CamelToSnakeCase(str string) string

CamelToSnakeCase converts a given camelCase string to snake_case format.

func CheckMetadataKeyAndValueLength

func CheckMetadataKeyAndValueLength(limit int, metadata map[string]any) error

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 EnsureConfigFromEnvVars

func EnsureConfigFromEnvVars(s any) any

EnsureConfigFromEnvVars ensures that an interface will be settled using SetConfigFromEnvVars anyway.

func GetenvBoolOrDefault

func GetenvBoolOrDefault(key string, defaultValue bool) bool

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

func GetenvIntOrDefault(key string, defaultValue int64) int64

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

func GetenvOrDefault(key string, defaultValue string) string

GetenvOrDefault encapsulate built-in os.Getenv behavior but if key is not present it returns the defaultValue.

func IsNilOrEmpty

func IsNilOrEmpty(s *string) bool

IsNilOrEmpty returns a boolean indicating if a *string is nil or empty. It's use TrimSpace so, a string " " and "" will be considered empty

func IsUpper added in v1.1.0

func IsUpper(s string) error

IsUpper check if string is lower

func RemoveAccents

func RemoveAccents(word string) (string, error)

RemoveAccents removes accents of a given word and returns it

func RemoveSpaces

func RemoveSpaces(word string) string

RemoveSpaces removes spaces of a given word and returns it

func SetConfigFromEnvVars

func SetConfigFromEnvVars(s any) error

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 ValidateCountryAddress added in v1.1.0

func ValidateCountryAddress(country string) error

ValidateCountryAddress validate if country in object address contains in countries list using ISO 3166-1 alpha-2

func ValidateCurrency added in v1.1.0

func ValidateCurrency(code string) error

ValidateCurrency validate if code contains in currencies list using ISO 4217

func ValidateType added in v1.1.0

func ValidateType(t string) error

ValidateType validate type values of currencies

Types

type App

type App interface {
	Run(launcher *Launcher) error
}

App represents an application that will run as a deployable component. It's an entrypoint at main.go.

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 NewEntityNotFoundError

func NewEntityNotFoundError(entityType string) EntityNotFoundError

NewEntityNotFoundError creates an instance of EntityNotFoundError.

func WrapEntityNotFoundError

func WrapEntityNotFoundError(entityType string, err error) EntityNotFoundError

WrapEntityNotFoundError creates an instance of EntityNotFoundError.

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 ForbiddenError

type ForbiddenError struct {
	EntityType string
	Title      string
	Message    string
	Code       string
	Err        error
}

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 HTTPError

type HTTPError struct {
	EntityType string
	Title      string
	Message    string
	Code       string
	Err        error
}

HTTPError indicates a http error raised in a http client.

func (HTTPError) Error

func (e HTTPError) Error() string

type Launcher

type Launcher struct {
	Logger mlog.Logger

	Verbose bool
	// contains filtered or unexported fields
}

Launcher manages apps.

func NewLauncher

func NewLauncher(opts ...LauncherOption) *Launcher

NewLauncher create an instance of Launch.

func (*Launcher) Add

func (l *Launcher) Add(appName string, a App) *Launcher

Add runs an application in a goroutine.

func (*Launcher) Run

func (l *Launcher) Run()

Run run every application registered before with Run method.

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 UnauthorizedError

type UnauthorizedError struct {
	EntityType string
	Title      string
	Message    string
	Code       string
	Err        error
}

UnauthorizedError indicates an operation that couldn't be performant because there's no user authenticated.

func (UnauthorizedError) Error

func (e UnauthorizedError) Error() string

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

type ValidationError

type ValidationError struct {
	EntityType string
	Title      string
	Message    string
	Code       string
	Err        error
}

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.

Directories

Path Synopsis
net

Jump to

Keyboard shortcuts

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