config

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: LGPL-2.1 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	DotenvPath:            ".env",
	AwsParameterStorePath: os.Getenv("AWS_PARAMETER_STORE_PATH"),
}

DefaultOptions for LoadAll function

Functions

func IsLambda

func IsLambda() bool

IsLambda checks whether the code is running on lambda using predefined Lambda environment variables

func Load

func Load(dest interface{}) error

Load loads configurations from all sources with default options

func LoadFromAwsParameterStore

func LoadFromAwsParameterStore(dest map[string]string, path string, nextToken *string) error

LoadFromAwsParameterStore gets params from AWS Parameter Store and sets them to destination map

func LoadFromDotenv

func LoadFromDotenv(dest map[string]string, files ...string) error

LoadFromDotenv parses .env file and sets the values to destination map

func LoadFromEnv

func LoadFromEnv(dest map[string]string)

LoadFromEnv parses OS environment variables and set values to destination map

func LoadWithOptions

func LoadWithOptions(dest interface{}, opts Options) error

LoadWithOptions fills configuration from various sources into destination struct.

Overwriting order: .env file < environment variables < AWS Parameter Store

Types

type App

type App struct {
}

App holds app specific configurations

type Configuration

type Configuration struct {
	General
	Server
	DB
	JWT
}

Configuration holds data necessery for configuring application

func LoadAll

func LoadAll() (cfg Configuration, err error)

LoadAll returns all configurations for the app

type DB

type DB struct {
	Driver   string `env:"DB_DRIVER,notEmpty"`
	Host     string `env:"DB_HOST,notEmpty"`
	Port     int    `env:"DB_PORT,notEmpty"`
	Username string `env:"DB_USERNAME,notEmpty"`
	Password string `env:"DB_PASSWORD,notEmpty"`
	Database string `env:"DB_DATABASE,notEmpty"`
	// Logging  int    `env:"DB_LOGGING" envDefault:"1"` // -4=debug, 0=info, 4=warn, 8=error
	Params string `env:"DB_PARAMS"`
}

DB holds DB configurations

type General

type General struct {
	Debug bool `env:"DEBUG" envDefault:"true"`
}

General holds general configurations

type JWT

type JWT struct {
	Secret               string `env:"JWT_SECRET,notEmpty"`
	Algorithm            string `env:"JWT_ALGORITHM" envDefault:"HS256"`
	DurationAccessToken  int    `env:"JWT_DURATION_ACCESS_TOKEN" envDefault:"3600"`   // 1 hour in second
	DurationRefreshToken int    `env:"JWT_DURATION_REFRESH_TOKEN" envDefault:"86400"` // 1 day in second
}

JWT holds JWT configurations

type Options

type Options struct {
	// Support all options from env package
	env.Options
	// Default to .env at current path if empty
	DotenvPath string
	// Whether to load from AWS Parameter Store. Slashes are required: /path/prefix/
	AwsParameterStorePath string
}

Options for loading

type Server

type Server struct {
	// The port for the http server to listen on
	Port int `env:"SERVER_PORT" envDefault:"8080"`
	// ReadHeaderTimeout is the amount of time allowed to read request headers.
	ReadHeaderTimeout int `env:"SERVER_READ_HEADER_TIMEOUT" envDefault:"10"`
	// ReadTimeout is the maximum duration for reading the entire request, including the body
	ReadTimeout int `env:"SERVER_READ_TIMEOUT" envDefault:"30"`
	// WriteTimeout is the maximum duration before timing out writes of the response
	WriteTimeout int `env:"SERVER_WRITE_TIMEOUT" envDefault:"60"`
	// CORS settings
	AllowOrigins []string `env:"SERVER_ALLOW_ORIGINS" envDefault:"*"`
}

Server holds http server configurations

type SsmSvc

type SsmSvc interface {
	GetParametersByPath(input *ssm.GetParametersByPathInput) (*ssm.GetParametersByPathOutput, error)
}

SsmSvc to generate the mock functions mockgen -destination config/mock_ssm_test.go -package config github.com/alextanhongpin/go-config/config SsmSvc

Jump to

Keyboard shortcuts

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