Documentation
¶
Index ¶
- Variables
- func EmailFieldValidator(fieldLevel validator.FieldLevel) bool
- func MustGetEnv(name string) string
- func NameFieldValidator(fieldLevel validator.FieldLevel) bool
- func NewValidator(ctx context.Context) *goValidator.Validate
- func PasswordFieldValidator(fieldLevel validator.FieldLevel) bool
- func RegisterCustomFieldValidators(validator *goValidator.Validate, customFieldValidators CustomFieldValidators)
- func UsernameFieldValidator(fieldLevel validator.FieldLevel) bool
- func ValidateEmail(email string) error
- func ValidateName(name string) error
- func ValidatePassword(password string) error
- func ValidateUsername(username string) error
- func WrapError(err error) error
- func WrapErrorWithPrefix(contextualErrorMessage string, err error) error
- type APIError
- type CustomFieldValidators
- type GetFlagOrEnvFn
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 ¶
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 ValidateName ¶
func ValidatePassword ¶
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 WrapError ¶
Returns a new error which contains the stacktrace along with the original error message.
func WrapErrorWithPrefix ¶
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 ¶
Returns an APIError, constructed using the given error message.
type CustomFieldValidators ¶
type CustomFieldValidators = map[string]goValidator.Func
type GetFlagOrEnvFn ¶
func CreateGetFlagOrEnvValueFn ¶
func CreateGetFlagOrEnvValueFn(envPrefix string) GetFlagOrEnvFn
Usage : flagSet.VisitAll(getFlagOrEnvValue("USERS_MICROSERVICE_"))
Click to show internal directories.
Click to hide internal directories.