config

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: LGPL-2.1 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 < OS 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 {
	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:"0"` // -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