config

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config implements app configuration

🚀 Иерархия приоритетов (от низшего к высшему):

  • Defaults (прописаны в коде) — база, чтобы сервис не упал.
  • Config File (YAML/JSON) — настройки для конкретного окружения (dev/prod).
  • Environment Variables (ENV) — настройки от Docker/K8s (пароли, хосты).
  • Flags (Флаги запуска) — самый высокий приоритет для быстрой отладки

Index

Constants

View Source
const (
	FlagAppEnv                string = "env"
	FlagAppMaxListLimit       string = "app-max-list-limit"
	FlagAppTokenIssuer        string = "app-token-issuer"
	FlagAppCipherKey          string = "app-cipher-key"
	FlagAppAcceptTokenIssuers string = "app-accept-token-issuers"
)

App config flags

View Source
const (
	FlagAuthTCStartInterval      string = "auth-tc-start-interval"
	FlagAuthTCScheduleInterval   string = "auth-tc-schedule-interval"
	FlagAuthTCWorkerCount        string = "auth-tc-worker-count"
	FlagAuthTCDataCapacity       string = "auth-tc-data-capacity"
	FlagAuthTCCompleteProcessing string = "auth-tc-complete-processing"
	FlagAuthTCShutdownTimeout    string = "auth-tc-shutdown-timeout"
	FlagAuthTCTailInterval       string = "auth-tc-tail-interval"
	FlagAuthTCTailCut            string = "auth-tc-tail-cut"
)

auth tc config flags

View Source
const (
	FlagDataTCStartInterval      string = "data-tc-start-interval"
	FlagDataTCScheduleInterval   string = "data-tc-schedule-interval"
	FlagDataTCWorkerCount        string = "data-tc-worker-count"
	FlagDataTCDataCapacity       string = "data-tc-data-capacity"
	FlagDataTCCompleteProcessing string = "data-tc-complete-processing"
	FlagDataTCShutdownTimeout    string = "data-tc-shutdown-timeout"
	FlagDataTCTailInterval       string = "data-tc-tail-interval"
	FlagDataTCTailCut            string = "data-tc-tail-cut"
)

data tc config flags

View Source
const (
	FlagAuthJWTSecret          string = "auth-jwt-secret"
	FlagAuthJWTSigningMethod   string = "auth-jwt-signing-method"
	FlagAuthAccessTokenTTL     string = "auth-access-token-ttl"
	FlagAuthRefreshTokenTTL    string = "auth-refresh-token-ttl"
	FlagAuthRSAPrivateKeyPath  string = "auth-rsa-private-key-path"
	FlagAuthMasterPasswordSalt string = "auth-master-password-salt"
)

Auth config flags

View Source
const (
	FlagDBDSN             string = "db-dsn"
	FlagDBDriver          string = "db-driver"
	FlagDBMaxOpenConns    string = "db-max-open-conns"
	FlagDBMaxIdleConns    string = "db-max-idle-conns"
	FlagDBMaxIdleLifetime string = "db-max-idle-lifetime"
	FlagDBConnTimeout     string = "db-conn-timeout"
)

DB config flags

View Source
const (
	FlagGRPCAddress          string = "grpc-address"
	FlagGRPCMaxConnIdle      string = "grpc-max-conn-idle"
	FlagGRPCMaxConnAge       string = "grpc-max-conn-age"
	FlagGRPCMaxConnAgeGrace  string = "grpc-max-conn-age-grace"
	FlagGRPCTimeout          string = "grpc-timeout"
	FlagGRPCKeepAliveTime    string = "grpc-keep-alive-time"
	FlagGRPCKeepAliveTimeout string = "grpc-keep-alive-timeout"
	FlagGRPCShutdownTimeout  string = "grpc-shutdown-timeout"
)

gRPC config flags

View Source
const (
	FlagHTTPAddress            string = "http-address"
	FlagHTTPReadTimeout        string = "http-read-timeout"
	FlagHTTPWriteTimeout       string = "http-write-timeout"
	FlagHTTPIdleTimeout        string = "http-idle-timeout"
	FlagHTTPShutdownTimeout    string = "http-shutdown-timeout"
	FlagHTTPPrivateKeyPath     string = "http-private-key-path"
	FlagHTTPCertificatePath    string = "http-certificate-path"
	FlagHTTPSecure             string = "http-secure"
	FlagHTTPMaxRequestBodySize string = "http-max-request-body-size"
)

http config flags

View Source
const (
	FlagLogLevel  string = "log-level"
	FlagLogFormat string = "log-format"
)

log config flags

View Source
const (
	FlagTelemetryEnabled          string = "telemetry-enabled"
	FlagTelemetryServiceName      string = "telemetry-service-name"
	FlagTelemetryExporterEndpoint string = "telemetry-exporter-endpoint"
	FlagTelemetrySampleRate       string = "telemetry-sample-rate"
	FlagTelemetryTimeout          string = "telemetry-timeout"
)

telemetry

View Source
const EnvConfig string = "CONFIG_PATH"

EnvConfig - файл конфигурации

View Source
const FlagConfig = "config-path"

FlagConfig - файл конфигурации

Variables

View Source
var (
	AppName      string
	AppVersion   string
	AppBuildTime string
)

linker params

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	Env                AppEnv   `mapstructure:"env" json:"env,omitempty" yaml:"env,omitempty"` // dev, prod, test
	MaxListLimit       int      `mapstructure:"max_list_limit" json:"max_list_limit,omitempty" yaml:"max_list_limit,omitempty"`
	TokenIssuer        string   `mapstructure:"token_issuer" json:"token_issuer,omitempty" yaml:"token_issuer,omitempty"`
	AcceptTokenIssuers []string `mapstructure:"accept_token_issuers" json:"accept_token_issuers,omitempty" yaml:"accept_token_issuers,omitempty"`
	CipherKey          string   `mapstructure:"cipher_key" json:"cipher_key,omitempty" yaml:"cipher_key,omitempty"`
}

AppConfig — метаданные сервиса

func NewAppConfig

func NewAppConfig(
	env AppEnv,
	maxListLimit int,
	acceptTokenIssuers []string,
	cipherKey string,
) *AppConfig

func NewDefaultAppConfig

func NewDefaultAppConfig() *AppConfig

func (*AppConfig) Validate

func (ac *AppConfig) Validate() error

type AppEnv

type AppEnv string
const (
	AppEnvProduction  AppEnv = "prod"
	AppEnvDevelopment AppEnv = "dev"
	AppEnvTest        AppEnv = "test"
)

app env enum

func (AppEnv) Exists

func (ae AppEnv) Exists() bool

type Config

type Config struct {
	App       *AppConfig              `mapstructure:"app" json:"app,omitempty" yaml:"app,omitempty"`
	AuthTC    *TailCutterConfig       `mapstructure:"auth_tc" json:"auth_tc,omitempty" yaml:"auth_tc,omitempty"`
	DataTC    *TailCutterConfig       `mapstructure:"data_tc" json:"data_tc,omitempty" yaml:"data_tc,omitempty"`
	Auth      *config.AuthConfig      `mapstructure:"auth" json:"auth,omitempty" yaml:"auth,omitempty"`
	HTTP      *config.HTTPConfig      `mapstructure:"http" json:"http,omitempty" yaml:"http,omitempty"`
	GRPC      *config.GRPCConfig      `mapstructure:"grpc" json:"grpc,omitempty" yaml:"grpc,omitempty"`
	Log       *config.LogConfig       `mapstructure:"log" json:"log,omitempty" yaml:"log,omitempty"`
	DB        *config.DBConfig        `mapstructure:"db" json:"db,omitempty" yaml:"db,omitempty"`
	Telemetry *config.TelemetryConfig `mapstructure:"telemetry" json:"telemetry,omitempty" yaml:"telemetry,omitempty"`
}

func Load

func Load() (*Config, error)

Load собирает конфигурацию из: Flags -> ENV -> YAML -> Defaults

func NewConfig

func NewConfig(
	app *AppConfig,
	authTC *TailCutterConfig,
	dataTC *TailCutterConfig,
	auth *config.AuthConfig,
	HTTP *config.HTTPConfig,
	GRPC *config.GRPCConfig,
	log *config.LogConfig,
	db *config.DBConfig,
	telemetry *config.TelemetryConfig,
) *Config

func NewDefaultConfig

func NewDefaultConfig() *Config

func NewEmptyConfig

func NewEmptyConfig() *Config

func (*Config) Validate

func (c *Config) Validate() error

type TailCutterConfig added in v0.0.5

type TailCutterConfig struct {
	StartInterval      time.Duration `mapstructure:"start_interval" json:"start_interval,omitempty" yaml:"start_interval,omitempty"`
	ScheduleInterval   time.Duration `mapstructure:"schedule_interval" json:"schedule_interval,omitempty" yaml:"schedule_interval,omitempty"`
	WorkerCount        int           `mapstructure:"worker_count" json:"worker_count,omitempty" yaml:"worker_count,omitempty"`
	DataCapacity       int           `mapstructure:"data_capacity" json:"data_capacity,omitempty" yaml:"data_capacity,omitempty"`
	CompleteProcessing bool          `mapstructure:"complete_processing" json:"complete_processing,omitempty" yaml:"complete_processing,omitempty"`
	ShutdownTimeout    time.Duration `mapstructure:"shutdown_timeout" json:"shutdown_timeout,omitempty" yaml:"shutdown_timeout,omitempty"`
	TailInterval       time.Duration `mapstructure:"tail_interval" json:"tail_interval,omitempty" yaml:"tail_interval,omitempty"`
	TailCut            bool          `mapstructure:"tail_cut" json:"tail_cut,omitempty" yaml:"tail_cut,omitempty"`
}

func NewDefaultTailCutterConfig added in v0.0.5

func NewDefaultTailCutterConfig() *TailCutterConfig

func NewTailCutterConfig added in v0.0.5

func NewTailCutterConfig(
	startInterval time.Duration,
	scheduleInterval time.Duration,
	workerCount int,
	dataCapacity int,
	completeProcessing bool,
	shutdownTimeout time.Duration,
	tailInterval time.Duration,
	tailCut bool,
) *TailCutterConfig

func (*TailCutterConfig) Validate added in v0.0.5

func (tcc *TailCutterConfig) Validate() error

Jump to

Keyboard shortcuts

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