config

package
v0.0.0-...-1185af5 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config provides configuration loader based on env vars.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithEnvFiles

func WithEnvFiles(files ...string) error

WithEnvFiles populates env vars from provided files.

It returns an error if file does not exist.

Types

type Config

type Config struct {
	ServiceName    string   `envconfig:"SERVICE_NAME"`
	AppGRPCPort    int      `envconfig:"APP_GRPC_PORT" default:"8000"`
	AppRESTPort    int      `envconfig:"APP_REST_PORT" default:"8080"`
	AppMetricsPort int      `envconfig:"APP_METRICS_PORT" default:"8080"`
	Environment    string   `envconfig:"ENVIRONMENT" default:"dev"`
	PostgresDB     DBConfig `split_words:"true"`
	Log            LoggerConfig
}

Config represents config with variables needed for an app.

func GetConfig

func GetConfig() (*Config, error)

GetConfig returns service config, filled from environment variables.

func (*Config) IsDev

func (c *Config) IsDev() bool

IsDev returns true for development environment.

func (*Config) IsTest

func (c *Config) IsTest() bool

IsTest returns true for testing environment.

type DBConfig

type DBConfig struct {
	DSN          string        `envconfig:"DATABASE_DSN" required:"true"`
	MaxLifetime  time.Duration `envconfig:"MAX_LIFETIME" default:"4h"`
	MaxIdleConns int           `envconfig:"MAX_IDLE_CONNECTIONS" default:"20"`
	MaxOpenConns int           `envconfig:"MAX_OPEN_CONNECTIONS" default:"20"`
	DriverName   string
}

DBConfig represents the DB configuration fields and values.

type LoggerConfig

type LoggerConfig struct {
	Level      zapcore.Level `envconfig:"LOG_LEVEL" default:"error"`
	FieldNames string        `envconfig:"LOG_FILENAMES" default:"true"`
	Output     io.Writer
	// LockTime disables time variance in logger.
	LockTime bool

	// CallerSkip configures how deeply func calls should be skipped, default 1.
	CallerSkip int
}

LoggerConfig is log configuration.

Jump to

Keyboard shortcuts

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