Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSourceEmpty error = errors.New("field source (path to file or conn str to db) is empty")
)

Functions

This section is empty.

Types

type AdminUser added in v0.9.3

type AdminUser struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type AppConfig

type AppConfig struct {
	ServerCfg  ServerConfig         `json:"server"`
	DataSource DataSourceConfig     `json:"data_source"`
	Logging    LoggingConfig        `json:"logging"`
	Security   GlobalSecurityConfig `json:"security"`
}

func ReadAppConfig added in v0.9.2

func ReadAppConfig(pathToConfig string) (*AppConfig, error)

func (*AppConfig) Validate added in v0.9.2

func (cfg *AppConfig) Validate()

type AppenderConfig added in v0.1.3

type AppenderConfig struct {
	Type        AppenderType       `json:"type"`
	Enabled     bool               `json:"enabled"`
	Level       string             `json:"level"`
	Destination *DestinationConfig `json:"destination"`
}

type AppenderType added in v0.1.3

type AppenderType string

Composing structs for unmarshalling. Writer is lumberjack's setup struct. It's annotated for JSON out-of-the-box. Logrus is for logging level and log output settings.

const (
	RollingFile AppenderType = "rolling_file"
	Console     AppenderType = "console"
)

type CredentialsConfig added in v0.9.2

type CredentialsConfig struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type DataSourceConfig added in v0.9.2

type DataSourceConfig struct {
	Type        DataSourceType                  `json:"type"`
	Source      string                          `json:"source"`
	Credentials *CredentialsConfig              `json:"credentials"`
	Options     map[DataSourceConnOption]string `json:"options"`
}

DataSourceConfig represent source where we can get

  • We attempt to provide config that easily could be used with any datasource:
  • - json file (simplest RO mode)
  • - mongodb (but here we have very simple question how to pass parameters)
  • Source contains:
  • 1) if Type is FILE - full path to Json File
  • 2) if Type is REDIS - redis server address i.e. localhost:6739
  • Options are connection options, see - https://www.mongodb.com/docs/drivers/go/current/fundamentals/connection/#std-label-golang-connection-guide
  • Here we should have Validator too
  • Credentials contains Username && Password could be null id authorization is not required: *

func (*DataSourceConfig) Validate added in v0.9.2

func (cfg *DataSourceConfig) Validate() error

type DataSourceConnOption added in v0.9.2

type DataSourceConnOption string
const (
	// DbNumber is a REDIS connection options, here we expect to receive int in a string
	DbNumber DataSourceConnOption = "db_number"
	// UseTls is a REDIS option to set up tls.Config and use TLS connection, here we expect to receive bool value in a string
	UseTls DataSourceConnOption = "use_tls"
	// InsecureTls is a REDIS option to set up TLSConfig: &tls.Config{InsecureSkipVerify: true}, here we expect to receive bool value in a string
	InsecureTls DataSourceConnOption = "allow_insecure_tls"
	// Namespace is a prefix before any key
	Namespace DataSourceConnOption = "namespace"
)
const (
	OperationTimeout       DataSourceConnOption = "timeoutMS"
	ConnectionTimeout      DataSourceConnOption = "connectTimeoutMS"
	ConnectionsPool        DataSourceConnOption = "maxPoolSize"
	ReplicaSet             DataSourceConnOption = "replicaSet"
	MaxIdleTime            DataSourceConnOption = "maxIdleTimeMS"
	SocketTimeout          DataSourceConnOption = "socketTimeoutMS"
	ServerSelectionTimeout DataSourceConnOption = "serverSelectionTimeoutMS"
	HeartbeatFrequency     DataSourceConnOption = "heartbeatFrequencyMS"
	Tls                    DataSourceConnOption = "tls"
	WriteConcern           DataSourceConnOption = "w"
	DirectConnection       DataSourceConnOption = "directConnection"
)

type DataSourceType added in v0.9.2

type DataSourceType string
const (
	FILE DataSourceType = "file"
	// MONGODB TODO (UMV): Mongo won't be using for sometime, maybe it will be removed completely
	MONGODB DataSourceType = "mongodb"
	// REDIS : redis server should be running with dump every write on a disk (AOF)
	REDIS DataSourceType = "redis"
)

type DestinationConfig added in v0.1.3

type DestinationConfig struct {
	File       AppenderType `json:"file"`
	BufferSize int          `json:"buffer_size"`
	MaxSize    int          `json:"max_size"`
	MaxAge     int          `json:"max_age"`
	MaxBackups int          `json:"max_backups"`
	LocalTime  bool         `json:"local_time"`
}

type GlobalSecurityConfig added in v0.9.3

type GlobalSecurityConfig struct {
	AllowedHosts      []string  `json:"allowed_hosts"`
	AdminApiUrlPrefix string    `json:"admin_api_url_prefix"`
	Admin             AdminUser `json:"admin"`
}

type LoggingConfig added in v0.1.3

type LoggingConfig struct {
	Level          string           `json:"level"`
	Appenders      []AppenderConfig `json:"appenders"`
	ConsoleOutHTTP bool             `json:"http_console_out"`
	LogHTTP        bool             `json:"http_log"`
}

func (*LoggingConfig) Validate added in v0.9.2

func (cfg *LoggingConfig) Validate() error

type RedisConfig added in v0.9.2

type RedisConfig struct {
	Address   string `json:"address" example:"localhost:6379"`
	Password  string `json:"password"`
	DbNumber  int    `json:"db_number"`
	Namespace string `json:"namespace"`
	// MaxRetries is a number of attempts to
	MaxRetries int `json:"max_retries"`
	// MinRetryBackoff is a backoff in milliseconds
	MinRetryBackoff int `json:"min_retry_backoff"`
	MaxRetryBackoff int `json:"max_retry_backoff"`
	// go-redis dial timeout option is time, here we simplify config we assume here Seconds as a time value, 0 means no timeout
	DialTimeout uint `json:"dial_timeout"`
	// go-redis read timeout option is time, here we simplify config we assume here Seconds as a time value, 0 means no timeout
	ReadTimeout uint `json:"read_timeout"`
	// go-redis write timeout option is time, here we simplify config we assume here Seconds as a time value, 0 means no timeout
	WriteTimeout uint `json:"write_timeout"`
	PoolSize     uint `json:"pool_size"`
	// go-redis pool timeout option is time, here we simplify config we assume here Seconds as a time value, 0 means 1 sec to pool timeout
	PoolTimeout uint `json:"pool_timeout"`
	MinIdleConn int  `json:"min_idle_conn"`
	MaxIdleConn int  `json:"max_idle_conn"`
	// default is 30 min (go-redis), 0 disable max timeout (pass -1 to go-redis)
	ConnIdleTimeout uint `json:"conn_idle_timeout"`
	// by default go-redis do not close idle connections
	ConnMaxLifetimeTimeout int         `json:"conn_max_lifetime_timeout"`
	ReadOnlySlaveEnabled   bool        `json:"read_only_slave_enabled"`
	TlsCfg                 *tls.Config `json:"tls_cfg"`
}

RedisConfig is a simplified redis.Options config

type Schema

type Schema string
const (
	HTTP  Schema = "http"
	HTTPS Schema = "https"
)

type SecurityConfig

type SecurityConfig struct {
	CertificateFile string `json:"certificate_file" example:"./certificates/server.crt"`
	KeyFile         string `json:"key_file" example:"./certificates/server.key"`
}

type ServerConfig

type ServerConfig struct {
	Schema          Schema          `json:"schema" example:"http or https"`
	Address         string          `json:"address" example:"127.0.0.1 or mydomain.com"`
	Port            int             `json:"port" example:"8080"`
	Security        *SecurityConfig `json:"security"`
	SecretFile      string          `json:"secret_file" example:"./keyfile"`
	ShutdownTimeout time.Duration   `json:"shutdown_timeout"`
}

func (*ServerConfig) Validate added in v0.9.2

func (cfg *ServerConfig) Validate() error

type ValidatingConfig added in v0.9.2

type ValidatingConfig interface {
	Validate() error
}

ValidatingConfig is interface that contains config struct and Validate method to check whether config can be used further or not

Jump to

Keyboard shortcuts

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