config

package
v0.0.0-...-9c786f9 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package config is responsible for reading all environment variables and set up the base configuration for a functional application

Index

Constants

View Source
const Activated string = "yes"

Activated - "yes" keyword to activate a service

View Source
const PrefixJtiBlacklist string = "gorest-blacklist-jti:"

PrefixJtiBlacklist - to manage JWT blacklist in Redis database

Variables

This section is empty.

Functions

func Config

func Config() (err error)

Config - load all the configurations

func Env

func Env() error

Env - load the configurations from .env

func InvalidateJWT

func InvalidateJWT() bool

InvalidateJWT returns true when this feature is enabled in .env

func Is2FA

func Is2FA() bool

Is2FA returns true when two-factor authentication is enabled in .env

func Is2FADoubleHash

func Is2FADoubleHash() bool

Is2FADoubleHash returns true when double hashing is enabled in .env

func IsAuthCookie

func IsAuthCookie() bool

IsAuthCookie returns true when auth cookie is enabled in .env

func IsBasicAuth

func IsBasicAuth() bool

IsBasicAuth returns true when basic auth is enabled in .env

func IsCORS

func IsCORS() bool

IsCORS returns true when CORS is enabled in .env

func IsCipher

func IsCipher() bool

IsCipher returns true when encryption at rest is enabled in .env

func IsEmailService

func IsEmailService() bool

IsEmailService returns true when email service is enabled in .env

func IsEmailVerificationCodeUUIDv4

func IsEmailVerificationCodeUUIDv4() bool

IsEmailVerificationCodeUUIDv4 returns true when it is enabled in .env

func IsEmailVerificationService

func IsEmailVerificationService() bool

IsEmailVerificationService returns true when it is enabled in .env

func IsHashPass

func IsHashPass() bool

IsHashPass returns true when password hashing is enabled in .env

func IsJWT

func IsJWT() bool

IsJWT returns true when JWT is enabled in .env

func IsMongo

func IsMongo() bool

IsMongo returns true when Mongo is enabled in .env

func IsOriginCheck

func IsOriginCheck() bool

IsOriginCheck returns true when origin check is enabled in .env

func IsPassRecoveryService

func IsPassRecoveryService() bool

IsPassRecoveryService returns true when it is enabled in .env

func IsPasswordRecoverCodeUUIDv4

func IsPasswordRecoverCodeUUIDv4() bool

IsPasswordRecoverCodeUUIDv4 returns true when it is enabled in .env

func IsProd

func IsProd() bool

IsProd returns true when app is running in production mode

func IsRDBMS

func IsRDBMS() bool

IsRDBMS returns true when RDBMS is enabled in .env

func IsRateLimit

func IsRateLimit() bool

IsRateLimit returns true when rate limiting is enabled in .env

func IsRedis

func IsRedis() bool

IsRedis returns true when Redis is enabled in .env

func IsSentry

func IsSentry() bool

IsSentry returns true when sentry logger is enabled in .env

func IsTemplatingEngine

func IsTemplatingEngine() bool

IsTemplatingEngine returns true when serving HTML is enabled in .env

func IsWAF

func IsWAF() bool

IsWAF returns true when app firewall is enabled in .env

Types

type Configuration

type Configuration struct {
	Version    string
	Database   DatabaseConfig
	EmailConf  EmailConfig
	Logger     LoggerConfig
	Server     ServerConfig
	Security   SecurityConfig
	ViewConfig ViewConfig
}

Configuration - server and db configuration variables

func GetConfig

func GetConfig() *Configuration

GetConfig - return all the config variables

type DatabaseConfig

type DatabaseConfig struct {
	// relational database
	RDBMS RDBMS

	// redis database
	REDIS REDIS

	// mongo database
	MongoDB MongoDB
}

DatabaseConfig - all database variables

type EmailConfig

type EmailConfig struct {
	Activate     string
	Provider     string
	APIToken     string
	AddrFrom     string
	TrackOpens   bool
	TrackLinks   string
	DeliveryType string

	// for templated email
	EmailVerificationTemplateID int64
	PasswordRecoverTemplateID   int64
	EmailUpdateVerifyTemplateID int64
	EmailVerificationCodeUUIDv4 bool
	EmailVerificationCodeLength uint64
	PasswordRecoverCodeUUIDv4   bool
	PasswordRecoverCodeLength   uint64
	EmailVerificationTag        string
	PasswordRecoverTag          string
	HTMLModel                   string
	EmailVerifyValidityPeriod   uint64 // in seconds
	PassRecoverValidityPeriod   uint64 // in seconds
}

EmailConfig - for external email services

type LoggerConfig

type LoggerConfig struct {
	Activate           string
	SentryDsn          string
	PerformanceTracing string
	TracesSampleRate   string
}

LoggerConfig ...

type MongoDB

type MongoDB struct {
	Activate string
	Env      struct {
		AppName  string
		URI      string
		PoolSize uint64
		PoolMon  string
		ConnTTL  int
	}
}

MongoDB - mongo database variables

type RDBMS

type RDBMS struct {
	Activate string
	Env      struct {
		Driver   string
		Host     string
		Port     string
		TimeZone string
	}
	Access struct {
		DbName string
		User   string
		Pass   string
	}
	Ssl struct {
		Sslmode    string
		MinTLS     string
		RootCA     string
		ServerCert string
		ClientCert string
		ClientKey  string
	}
	Conn struct {
		MaxIdleConns    int
		MaxOpenConns    int
		ConnMaxLifetime time.Duration
	}
	Log struct {
		LogLevel int
	}
}

RDBMS - relational database variables

type REDIS

type REDIS struct {
	Activate string
	Env      struct {
		Host string
		Port string
	}
	Conn struct {
		PoolSize int
		ConnTTL  int
	}
}

REDIS - redis database variables

type SecurityConfig

type SecurityConfig struct {
	UserPassMinLength int

	MustBasicAuth string
	BasicAuth     struct {
		Username string
		Password string
	}

	MustJWT string
	JWT     middleware.JWTParameters

	InvalidateJWT string // when user logs off, invalidate the tokens

	AuthCookieActivate bool
	AuthCookiePath     string
	AuthCookieDomain   string
	AuthCookieSecure   bool
	AuthCookieHTTPOnly bool
	AuthCookieSameSite http.SameSite
	ServeJwtAsResBody  bool

	MustHash string
	HashPass lib.HashPassConfig
	HashSec  string // optional secret for argon2id hashing

	// data encryption at rest
	MustCipher bool
	CipherKey  []byte // for 256-bit ChaCha20-Poly1305
	Blake2bSec []byte // optional secret for blake2b hashing

	VerifyEmail bool
	RecoverPass bool

	MustFW   string
	Firewall struct {
		ListType string
		IP       string
	}

	MustCORS string
	CORS     []middleware.CORSPolicy

	CheckOrigin     string
	RateLimit       string
	TrustedPlatform string

	Must2FA string
	TwoFA   struct {
		Issuer string
		Crypto crypto.Hash
		Digits int

		Status Status2FA
		PathQR string

		DoubleHash bool
	}
}

SecurityConfig ...

type ServerConfig

type ServerConfig struct {
	ServerHost string
	ServerPort string // public port of server
	ServerEnv  string
}

ServerConfig ...

type Status2FA

type Status2FA struct {
	Verified string
	On       string
	Off      string
	Invalid  string
}

Status2FA - user's 2FA statuses

type ViewConfig

type ViewConfig struct {
	Activate  string
	Directory string
}

ViewConfig - HTML renderer

Jump to

Keyboard shortcuts

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