config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = types.Module{
	{CreateFunc: NewConfig},
	{CreateFunc: ConfigAdapter},
}

Functions

This section is empty.

Types

type Config

type Config struct {
	HTTP          HTTPServerConfig `yaml:"http"`
	GRPC          GRPCServerConfig `yaml:"grpc"`
	APM           ElasticAPMConfig `yaml:"apm"`
	Postgres      PostgresConfig   `yaml:"postgres"`
	ElasticSearch ElasticSearch    `yaml:"elastic_search"`
	Sentry        Sentry           `yaml:"sentry"`

	ReleaseID string
	Env       string `envconfig:"ENV" default:"development" required:"true" yaml:"env"`
	LogLevel  string `envconfig:"LOG_LEVEL" default:"info" yaml:"log_level"`
	AppName   string `envconfig:"APP_NAME" yaml:"app_name"`

	// DebugLog включает/выключает полные логи ответов (response payload).
	DebugLog bool `envconfig:"DEBUG_LOG" default:"false" yaml:"debug_log"`
}

func NewConfig

func NewConfig(configurators []Configure, releaseID ReleaseID) (*Config, error)

type ConfigAdapterIn

type ConfigAdapterIn struct {
	dig.In

	CustomConfigurators []Configure `group:"configurators"`
}

type Configure

type Configure func(cfg *Config) error

func ConfigAdapter

func ConfigAdapter(in ConfigAdapterIn) []Configure

type ElasticAPMConfig

type ElasticAPMConfig struct {
	ServiceName string `envconfig:"ELASTIC_APM_SERVICE_NAME" yaml:"service_name"`
	ServerURL   string `envconfig:"ELASTIC_APM_SERVER_URL" yaml:"server_url"`
	Environment string `envconfig:"ELASTIC_APM_ENVIRONMENT" yaml:"environment"`
}

type ElasticSearch

type ElasticSearch struct {
	// DSN представляет из себя строку, где URI:port нод кластера перечислены через запятую без пробелов
	// Например: 'http://es1.localhost.com:9200,http://es2.localhost.com:9200'
	DSN        string `envconfig:"ELASTIC_SEARCH_DSN" yaml:"dsn"`
	MaxRetries int    `envconfig:"ELASTIC_SEARCH_MAX_RETRIES" default:"5" required:"true" yaml:"max_retries"`
	WithLogger bool   `envconfig:"ELASTIC_WITH_LOGGER" default:"false" required:"true" yaml:"with_logger"`
}

type GRPCServerConfig

type GRPCServerConfig struct {
	ListenAddr               string        `envconfig:"GRPC_LISTEN_ADDR" required:"true" default:":9090" yaml:"listen_addr"`
	KeepaliveTime            time.Duration `envconfig:"GRPC_KEEPALIVE_TIME" default:"30s" yaml:"keepalive_time"`
	KeepaliveTimeout         time.Duration `envconfig:"GRPC_KEEPALIVE_TIMEOUT" default:"10s" yaml:"keepalive_timeout"`
	RegisterReflectionServer bool          `envconfig:"GRPC_REGISTER_REFLECTION_SERVER" default:"true" yaml:"register_reflection_server"`
}

type HTTPServerConfig

type HTTPServerConfig struct {
	ListenAddr       string        `envconfig:"HTTP_LISTEN_ADDR" required:"true" default:":8080" yaml:"listen_addr"`
	KeepaliveTime    time.Duration `envconfig:"HTTP_KEEPALIVE_TIME" default:"30s" yaml:"keepalive_time"`
	KeepaliveTimeout time.Duration `envconfig:"HTTP_KEEPALIVE_TIMEOUT" default:"10s" yaml:"keepalive_timeout"`
}

type PostgresConfig

type PostgresConfig struct {
	DSN                string        `envconfig:"DB_DSN" yaml:"dsn"`
	MaxOpenConnections int           `envconfig:"DB_MAX_OPEN_CONNECTIONS" default:"25" required:"true" yaml:"max_open_connections"`
	MaxIdleConnections int           `envconfig:"DB_MAX_IDLE_CONNECTIONS" default:"25" required:"true" yaml:"max_idle_connections"`
	ConnMaxLifetime    time.Duration `envconfig:"DB_CONN_MAX_LIFETIME" default:"5m" required:"true" yaml:"conn_max_lifetime"`
}

type ReleaseID

type ReleaseID string

type Sentry

type Sentry struct {
	DSN string `envconfig:"SENTRY_DSN" yaml:"sentry_dsn"`
}

Jump to

Keyboard shortcuts

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