utils

package
v0.0.0-...-9a1086c Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInternalServer = errors.New("internal server error")

Functions

func EmailFieldValidator

func EmailFieldValidator(fieldLevel validator.FieldLevel) bool

func MustGetEnv

func MustGetEnv(name string) string

Returns the value of the given environment variable.

Panics if the environment variable isn't set.

func NameFieldValidator

func NameFieldValidator(fieldLevel validator.FieldLevel) bool

func NewValidator

func NewValidator(ctx context.Context) *goValidator.Validate

func PasswordFieldValidator

func PasswordFieldValidator(fieldLevel validator.FieldLevel) bool

func RegisterCustomFieldValidators

func RegisterCustomFieldValidators(
	validator *goValidator.Validate,
	customFieldValidators CustomFieldValidators,
)

func UsernameFieldValidator

func UsernameFieldValidator(fieldLevel validator.FieldLevel) bool

func ValidateEmail

func ValidateEmail(email string) error

func ValidateName

func ValidateName(name string) error

func ValidatePassword

func ValidatePassword(password string) error

TODO : Validate password based on entropy.

       There is a very good library for this : passwordvalidator. But, it's not compatible with
       tinygo.

	Password entropy refers to how unpredictable your password or phrase is, measured in bits.
	The following factors affect the password entropy :

	  (1) Length (in characters)

	  (2) Use of uppercase and lowercase letters, numeric characters and special symbols

	NOTE : Entropy and complexity aren’t the only password strength factors. Hackers can use
	       dictionary attacks to guess your credentials if you use a recognizable word or common
	       phrase in your password.

	REFERENCE : https://proton.me/blog/what-is-password-entropy.

func ValidateUsername

func ValidateUsername(username string) error

func WrapError

func WrapError(err error) error

Returns a new error which contains the stacktrace along with the original error message.

func WrapErrorWithPrefix

func WrapErrorWithPrefix(contextualErrorMessage string, err error) error

Returns a new error which contains :

(1) the stacktrace

(2) some contextual error message along with the original error message.

Types

type APIError

type APIError error

When the presentation layer (in this case, gRPC server) gets :

(1) an error of type APIError, it straight away sends that to the client.
    The gRPC error status code can be decided based on the concrete error type (like
    ErrUserNotFound).

(2) any other type of (unexpected) error, it logs that error and sends the ErrInternalServer back
    to the client.
    The gRPC error status code will always be codes.Internal.

func NewAPIError

func NewAPIError(message string) APIError

Returns an APIError, constructed using the given error message.

type CustomFieldValidators

type CustomFieldValidators = map[string]goValidator.Func

type GetFlagOrEnvFn

type GetFlagOrEnvFn = func(f *flag.Flag)

func CreateGetFlagOrEnvValueFn

func CreateGetFlagOrEnvValueFn(envPrefix string) GetFlagOrEnvFn

Usage : flagSet.VisitAll(getFlagOrEnvValue("USERS_MICROSERVICE_"))

Jump to

Keyboard shortcuts

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