utilities

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DBConnectionName const for the name of the Database connection.
	DBConnectionName string = "database"
	// RedisConnectionName const for the name of the Redis connection.
	RedisConnectionName string = "redis"
	// FiberConnectionName const for the name of the Fiber connection.
	FiberConnectionName string = "fiber"
)
View Source
const (
	// RoleNameUser const for the name of the user role.
	RoleNameUser int = 1
	// RoleNameModerator const for the name of the moderator role.
	RoleNameModerator int = 2
	// RoleNameAdmin const for the name of the admin role.
	RoleNameAdmin int = 3
)
View Source
const (
	// DefaultChars const for generate a new NanoID with default characters.
	DefaultChars string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz-"

	// UpperCaseChars const for generate a new NanoID with only upper case characters.
	UpperCaseChars string = "0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ-"

	// UpperCaseWithoutDashesChars const for generate a new NanoID
	// with only upper case characters, but without dashes.
	UpperCaseWithoutDashesChars string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

	// UpperCaseWithoutNumbersChars const for generate a new NanoID
	// with only upper case characters, but without numbers.
	UpperCaseWithoutNumbersChars string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_-"

	// LowerCaseChars const for generate a new NanoID with only lower case characters.
	LowerCaseChars string = "0123456789_abcdefghijklmnopqrstuvwxyz-"

	// LowerCaseWithoutDashesChars const for generate a new NanoID
	// with only lower case characters, but without dashes.
	LowerCaseWithoutDashesChars string = "0123456789abcdefghijklmnopqrstuvwxyz"

	// LowerCaseWithoutNumbersChars const for generate a new NanoID
	// with only lower case characters, but without numbers.
	LowerCaseWithoutNumbersChars string = "abcdefghijklmnopqrstuvwxyz_-"

	// OnlyNumbersChars const for generate a new NanoID with only numbers.
	OnlyNumbersChars string = "0123456789"
)

Variables

This section is empty.

Functions

func CheckForError added in v0.2.0

func CheckForError(ctx *fiber.Ctx, errFunc error, statusCode int, object, explanation string) error

CheckForError func for checking error in given function and returning error message.

func CheckForErrorWithStatusCode added in v0.3.0

func CheckForErrorWithStatusCode(ctx *fiber.Ctx, errFunc error, statusCode int, object, explanation string) error

CheckForErrorWithStatusCode func for checking error in given function and returning error message with status code.

func CheckForValidationError added in v0.7.0

func CheckForValidationError(ctx *fiber.Ctx, errFunc error, statusCode int, object string) error

CheckForValidationError func for checking validation errors in struct fields. See: https://github.com/go-playground/validator/blob/master/_examples/simple/main.go#L69

func ComparePasswords

func ComparePasswords(hashedPwd, inputPwd string) bool

ComparePasswords func for a comparing password.

func ConnectionURLBuilder

func ConnectionURLBuilder(name string) (string, error)

ConnectionURLBuilder func for building URL connection by given name. Allowed: database, redis, fiber

func GenerateCredential added in v0.0.2

func GenerateCredential(object, action string, isOwnCredential bool) string

GenerateCredential func for generating credential: <object>:<isOwn?>:<action>

func GenerateCredentialsByRole added in v0.1.0

func GenerateCredentialsByRole(role int) ([]string, error)

GenerateCredentialsByRole func for generating slice of the credentials, by given role number.

func GenerateErrorMessage added in v0.0.2

func GenerateErrorMessage(statusCode int, object, explanation string) string

GenerateErrorMessage func for generating error messages.

400 -> incorrect data for the <object> (<explanation>) 401 -> unauthorized request to the <object> (<explanation>) 403 -> access denied to the <object> (<explanation>) 404 -> <object> not found (<explanation>) 500 -> something went wrong with the <object> (<explanation>) XXX -> oops... something went wrong, but the status code is not handled (<code>)

func GenerateNewNanoID added in v0.0.3

func GenerateNewNanoID(chars string, size int) (string, error)

GenerateNewNanoID func for generate a new random string with nanoID. If chars is empty, looking for DefaultNanoIDChars const.

For example: ID length equals 18 characters with speed in 1kk IDs per second, ~81 years needed, in order to have a 1% probability of at least one collision. See: https://zelark.github.io/nano-id-cc/

func GeneratePassword

func GeneratePassword(p string) string

GeneratePassword func for a making hash & salt with user password.

func NewValidator

func NewValidator() *validator.Validate

NewValidator func for create a new validator for model fields.

func NormalizePassword

func NormalizePassword(p string) []byte

NormalizePassword func for a returning the users input as a byte slice.

func SearchStringInArray

func SearchStringInArray(value string, array []string) (ok bool)

SearchStringInArray func for searching value in []string array.

func StartServer

func StartServer(a *fiber.App)

StartServer func for starting a simple server.

func StartServerWithGracefulShutdown

func StartServerWithGracefulShutdown(a *fiber.App)

StartServerWithGracefulShutdown function for starting server with a graceful shutdown.

func ThrowJSONError added in v0.2.1

func ThrowJSONError(ctx *fiber.Ctx, statusCode int, object, explanation string) error

ThrowJSONError func for throwing error in JSON format.

func ThrowJSONErrorWithStatusCode added in v0.3.0

func ThrowJSONErrorWithStatusCode(ctx *fiber.Ctx, statusCode int, object, explanation string) error

ThrowJSONErrorWithStatusCode func for throwing error with status code in JSON format.

func ValidatorErrors

func ValidatorErrors(err error) map[string]string

ValidatorErrors func for show validation errors for each invalid fields.

Types

type TokenMetaData

type TokenMetaData struct {
	UserID      uuid.UUID
	Credentials []string
	Expire      int64
}

TokenMetadata struct to describe metadata in JWT.

func ExtractTokenMetaData

func ExtractTokenMetaData(c *fiber.Ctx) (*TokenMetaData, error)

ExtractTokenMetaData func to extract metadata from JWT.

func TokenValidateExpireTime

func TokenValidateExpireTime(ctx *fiber.Ctx) (*TokenMetaData, error)

TokenValidateExpireTime func for validating given JWT token with expire time.

func TokenValidateExpireTimeAndCredentials

func TokenValidateExpireTimeAndCredentials(ctx *fiber.Ctx, credentials []string) (*TokenMetaData, error)

TokenValidateExpireTimeAndCredentials func for validating given JWT token with expire time and credentials.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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