utils

package
v0.0.0-...-875f0a1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PROJECT_NAME                     = "PROJECT_NAME"
	FILE_SERVER_PATH                 = "FILE_SERVER_PATH"
	AES_SECRET                       = "AES_SECRET"
	USE_DB_MONGO                     = "USE_DB_MONGO"
	USE_DB_POSTGRES                  = "USE_DB_POSTGRES"
	USE_DB_VALKEY                    = "USE_DB_VALKEY"
	USE_JS_ALPINE                    = "USE_JS_ALPINE"
	USE_MW_LOCALISATION              = "USE_MW_LOCALISATION"
	USE_MW_SECURE_HEADERS            = "USE_MW_SECURE_HEADERS"
	USE_MW_RATE_LIMIT                = "USE_MW_RATE_LIMIT"
	MW_RATE_LIMITER_LIMIT            = "MW_RATE_LIMITER_LIMIT"
	MW_RATE_LIMITER_BURST            = "MW_RATE_LIMITER_BURST"
	USE_MW_LOG_AND_MONITOR_HEADERS   = "USE_MW_LOG_AND_MONITOR_HEADERS"
	USE_MW_CORS                      = "USE_MW_CORS"
	USE_MW_ETAG                      = "USE_MW_ETAG"
	USE_MW_VALIDATE_SANITISE_HEADERS = "USE_MW_VALIDATE_SANITISE_HEADERS"
	USE_MW_METHOD_OVERRIDE           = "USE_MW_METHOD_OVERRIDE"
	HTTP_PORT                        = "HTTP_PORT"
	MONGO_DB_NAME                    = "MONGO_DB_NAME"
	MONGO_USERNAME                   = "MONGO_USERNAME"
	MONGO_PASSWORD                   = "MONGO_PASSWORD"
	MONGO_HOST                       = "MONGO_HOST"
	MONGO_PORT                       = "MONGO_PORT"
)
View Source
const (
	MIN_NAME_LEN     = 2
	MIN_PASSWORD_LEN = 8

	MAX_NAME_LEN     = 64
	MAX_PASSWORD_LEN = 32
)

This is a standard configuration. Modify these to your needs.

Variables

This section is empty.

Functions

func AllConfigKeys

func AllConfigKeys() []string

func DecryptAES

func DecryptAES(secure string) (decoded string, err error)

Decrypt encrypted message using AES encryption. Make sure AES_SECRET key with value was added to environmental variables.

func EncryptAES

func EncryptAES(message string) (string, error)

Encrypt string message using AES encryption. Make sure AES_SECRET key with value was added to environmental variables.

func GetLocale

func GetLocale(ctx context.Context) (language string, currency string)

Helper function to get both language and currency from the context

func IsEmailCorrect

func IsEmailCorrect(email string) bool

This email validation method is bit more advanced than a simple regex. If, for any reason, this configuration will be too much (or less likely too little) for your project, modify this function by adding/removing advanced conditions or regex itself.

func IsNameCorrect

func IsNameCorrect(name string) bool

Quickly validate name/surname with the min/max system lenghts

func IsPasswordCorrect

func IsPasswordCorrect(pwd string) bool

Validate if password has correct lenght, has at least one number, uppercased, and special character

func IsURLSafe

func IsURLSafe(input string) bool

Check if given string is URL safe

func Ptr

func Ptr[T any](v T) *T

Return pointer of the value

Types

type Config

type Config struct {
	HTTP       *HTTPConfig
	Middleware *MiddlewareConfig
	Mongo      *MongoConfig
	Postgres   *PostgresConfig
	Valkey     *ValkeyConfig
}

Holds global configuration sourced from local .env file

func NewDefaultConfig

func NewDefaultConfig() (*Config, error)

Create new default config from the local .env file. If any part of the configuration will cause an error, will return an empty config (nil) and error message

type HTTPConfig

type HTTPConfig struct {
	FileServerPath string
	ImportAlpineJS bool
	Port           int
}

Configuration required for HTTP server

type MiddlewareConfig

type MiddlewareConfig struct {
	Localisation            bool
	SecureHeaders           bool
	RateLimit               bool
	RateLimiterLimit        *int
	RateLimiterBurst        *int
	LogAndMonitorHeaders    bool
	CORS                    bool
	ETAG                    bool
	ValidateSanitiseHeaders bool
	MethodOverride          bool
}

type MongoConfig

type MongoConfig struct {
	Username string
	Password string
	Host     string
	Port     string
	DBName   string
}

Required configuration for creating mongodb connection

func (*MongoConfig) Client

func (c *MongoConfig) Client() (*mongo.Client, error)

func (*MongoConfig) ConnectionString

func (c *MongoConfig) ConnectionString() string

type PostgresConfig

type PostgresConfig struct{}

Required configuration for creating postgres connection

type ValkeyConfig

type ValkeyConfig struct{}

Required configuration for creating valkey connection

Jump to

Keyboard shortcuts

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