Documentation
¶
Index ¶
- Constants
- func CheckForError(ctx *fiber.Ctx, errFunc error, statusCode int, object, explanation string) error
- func CheckForErrorWithStatusCode(ctx *fiber.Ctx, errFunc error, statusCode int, object, explanation string) error
- func CheckForValidationError(ctx *fiber.Ctx, errFunc error, statusCode int, object string) error
- func ComparePasswords(hashedPwd, inputPwd string) bool
- func ConnectionURLBuilder(name string) (string, error)
- func GenerateCredential(object, action string, isOwnCredential bool) string
- func GenerateCredentialsByRole(role int) ([]string, error)
- func GenerateErrorMessage(statusCode int, object, explanation string) string
- func GenerateNewNanoID(chars string, size int) (string, error)
- func GeneratePassword(p string) string
- func NewValidator() *validator.Validate
- func NormalizePassword(p string) []byte
- func SearchStringInArray(value string, array []string) (ok bool)
- func StartServer(a *fiber.App)
- func StartServerWithGracefulShutdown(a *fiber.App)
- func ThrowJSONError(ctx *fiber.Ctx, statusCode int, object, explanation string) error
- func ThrowJSONErrorWithStatusCode(ctx *fiber.Ctx, statusCode int, object, explanation string) error
- func ValidatorErrors(err error) map[string]string
- type TokenMetaData
Constants ¶
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" )
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 )
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
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
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 ¶
ComparePasswords func for a comparing password.
func ConnectionURLBuilder ¶
ConnectionURLBuilder func for building URL connection by given name. Allowed: database, redis, fiber
func GenerateCredential ¶ added in v0.0.2
GenerateCredential func for generating credential: <object>:<isOwn?>:<action>
func GenerateCredentialsByRole ¶ added in v0.1.0
GenerateCredentialsByRole func for generating slice of the credentials, by given role number.
func GenerateErrorMessage ¶ added in v0.0.2
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
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 ¶
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 ¶
NormalizePassword func for a returning the users input as a byte slice.
func SearchStringInArray ¶
SearchStringInArray func for searching value in []string array.
func StartServerWithGracefulShutdown ¶
func StartServerWithGracefulShutdown(a *fiber.App)
StartServerWithGracefulShutdown function for starting server with a graceful shutdown.
func ThrowJSONError ¶ added in v0.2.1
ThrowJSONError func for throwing error in JSON format.
func ThrowJSONErrorWithStatusCode ¶ added in v0.3.0
ThrowJSONErrorWithStatusCode func for throwing error with status code in JSON format.
func ValidatorErrors ¶
ValidatorErrors func for show validation errors for each invalid fields.
Types ¶
type TokenMetaData ¶
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.