utils

package
v0.0.0-...-0ac2d30 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CreateAccount string = "create_account"
	LogInAccount  string = "log_in_account"
)
View Source
const (
	ErrorBadRequest  string = "Bad request."
	ErrorServer      string = "Oops, something went wrong!"
	ErrorDiffEmail   string = "Oops, that didn't work - try again with a different email address."
	ErrorFailedLogin string = "Oops, failed to log in - try again!"
)
View Source
const (
	ErrorParse          string = "Failed to parse request body."
	ErrorAcctName       string = "Invalid `name`."
	ErrorAcctEmail      string = "Invalid `email`."
	ErrorAcctPW         string = "Invalid `password`."
	ErrorNonMatchPW     string = "Non-matching password inputs."
	ErrorCreateUser     string = "Failed create user transaction."
	ErrorFailedDB       string = "Failed DB operation."
	ErrorNoRowsAffected string = "result.RowsAffected == 0"
)
View Source
const DIGITS string = "0123456789"
View Source
const LOWERCASE_LETTERS string = "abcdefghijklmnopqrstuvwxyz"
View Source
const SLUG_ALPHABET = UPPERCASE_LETTERS + LOWERCASE_LETTERS + DIGITS + "_-"
View Source
const SPECIAL_CHARS string = "`~!@#$%^&*()-=_+,./<>?;':\"[]\\{}|"
View Source
const UPPERCASE_LETTERS string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Variables

View Source
var (
	SlugRegexp  = regexp.MustCompile(`^[\w-]{32}$`)
	TokenRegexp = regexp.MustCompile(`^[\w-]{144}$`)
	RowsRegexp  = regexp.MustCompile(`^result.RowsAffected \([0-9]+\) > 1$`)
)

Functions

func GeneratePassword

func GeneratePassword(n int) (string, error)

func GenerateSalt

func GenerateSalt(n int) (string, error)

func GenerateSlug

func GenerateSlug(n int) (string, error)

func GenerateUserCredentials

func GenerateUserCredentials(password string) (string, []byte, error)

func HashToken

func HashToken(token string) []byte

func RespondWithError

func RespondWithError(
	c *fiber.Ctx,
	statusCode int,
	detail string,
	fieldErrors map[string][]string,
	nonFieldErrors []string,
) error

Types

type ErrorResponseBody

type ErrorResponseBody struct {
	Detail         string              `json:"detail"`
	FieldErrors    map[string][]string `json:"field_errors"`
	NonFieldErrors []string            `json:"non_field_errors"`
}

type VaultsErrorResponseBody

type VaultsErrorResponseBody struct {
	ClientOperation string `json:"client_operation"`
	Message         string `json:"message"`
	ContextString   string `json:"context_string"`
	RequestBody     string `json:"request_body"`
	Detail          string `json:"detail"`
}

Jump to

Keyboard shortcuts

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