config

package module
v0.1.59 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 16 Imported by: 25

README

Example of the standard "common" block

[common]

# Applications name
name = "My service"

# Applications description
description = "The simple sample service"

# Applications class
class = "relay"

# Write logs in local time, by default in UTC
#log-local-time = true

# Directory where the logs are written. If a relative path is specified, then it is used relative to the executable file directory
log-dir = "logs"

# Logging level
# Valid valued EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO, DEBUG, TRACE1, TRACE2, TRACE3, TRACE4
# Default: DEBUG
log-level = "INFO"

# Log buffer size in bytes, data is pushed to the file when buffer is full, 0 - do not use buffering
log-buffer-size = 512

# If log buffering is used (log-buffer-size> 0), then this is the time in seconds after which automatic pushing to the file of a buffer that is not completely filled is performed.
# By default (value of 0) 1 second used
log-buffer-delay = 3

# Maximum line length in the log
log-max-string-len = 10000

# The maximum number of cores that the application can use. Default 0 - all available
go-max-procs = 4

# The period to write to the memory statistics statistics log in seconds
mem-stats-period = 1800

# Logging level for memory usage statistics
mem-stats-level = "INFO"

# Statistics collection period in seconds
load-avg-period = 60

# Is profiler enabled by default?
profiler-enabled = false 

# Extended profiling. Do not turn on without need!
deep-profiling = false

# Disabled endpoints
disabled-endpoints = []

# The minimum data size for gzip packing if it required when sending via HTTP. Smaller size will be send without packing
# 0  - do not pack 
# <0 - always pack
min-size-for-gzip = 256

Documentation

Index

Constants

View Source
const (
	// AuthMethodBasic --
	AuthMethodBasic = "basic"
	// AuthMethodJWT --
	AuthMethodJWT = "jwt"
	// AuthMethodKrb5 --
	AuthMethodKrb5 = "krb5"
)
View Source
const (
	// ListenerDefaultTimeout --
	ListenerDefaultTimeout = Duration(5 * time.Second)

	// ClientDefaultTimeout --
	ClientDefaultTimeout = Duration(5 * time.Second)

	// JWTdefaultLifetimeAccess --
	JWTdefaultLifetimeAccess = Duration(time.Hour)

	// JWTdefaultLifetimeRefresh --
	JWTdefaultLifetimeRefresh = Duration(2 * 24 * time.Hour)
)

Variables

This section is empty.

Functions

func AddAuthMethod added in v0.1.28

func AddAuthMethod(name string, options any) (err error)

AddAuthMethod --

func AddFilter added in v0.1.8

func AddFilter(re string, replaceTo string) error

AddFilter --

func Check

func Check(cfg any, list []any) error

Check --

func ConvExtra added in v0.1.45

func ConvExtra(src *any, obj any) (err error)

func Embed added in v0.1.58

func Embed(fs *embed.FS)

func GetConfig

func GetConfig() any

GetConfig --

func GetSecuredText added in v0.1.8

func GetSecuredText() string

GetSecuredText -- get prepared configuration text with securing

func GetText

func GetText() string

GetText -- get prepared configuration text

func LoadFile

func LoadFile(fileName string, cfg any) (err error)

LoadFile parses the specified file into a Config object

func SetCommon added in v0.1.41

func SetCommon(cc *Common)

SetCommon --

func SetListener added in v0.1.55

func SetListener(cc *Listener)

SetListener --

func StringSlice2Map added in v0.1.32

func StringSlice2Map(src []string, conv func(name string) string) (dst misc.BoolMap)

StringSlice2Map --

Types

type App added in v0.1.23

type App interface {
	Check() (err error)
}

App --

type Auth added in v0.1.28

type Auth struct {
	EndpointsSlice map[string][]string     `toml:"endpoints"`
	Endpoints      map[string]misc.BoolMap `toml:"-"`

	UsersMap misc.StringMap  `toml:"users"`
	Users    map[string]User `toml:"-"`

	Realm string `toml:"realm"`

	Methods             map[string]*AuthMethod `toml:"methods"`
	LocalAdminGroups    []string               `toml:"local-auth-groups"`
	LocalAdminGroupsMap misc.BoolMap           `toml:"-"`
}

Auth --

func (*Auth) Check added in v0.1.28

func (x *Auth) Check(cfg any) (err error)

Check --

type AuthMethod added in v0.1.28

type AuthMethod struct {
	Enabled bool `toml:"enabled"`
	Score   int  `toml:"score"`
	Options any  `toml:"options"`
}

AuthMethod --

type Common

type Common struct {
	Name        string `toml:"name"`
	Description string `toml:"description"`
	Class       string `toml:"class"`

	LogLocalTime    bool           `toml:"log-local-time"`
	LogDir          string         `toml:"log-dir"`
	LogLevel        string         `toml:"log-level"`  // default
	LogLevels       misc.StringMap `toml:"log-levels"` // by facilities
	LogBufferSize   int            `toml:"log-buffer-size"`
	LogBufferDelay  Duration       `toml:"log-buffer-delay"`
	LogMaxStringLen int            `toml:"log-max-string-len"`

	GoMaxProcs int `toml:"go-max-procs"`

	MemStatsPeriod Duration `toml:"mem-stats-period"`
	MemStatsLevel  string   `toml:"mem-stats-level"`

	LoadAvgPeriod Duration `toml:"load-avg-period"`

	ProfilerEnabled bool `toml:"profiler-enabled"`
	DeepProfiling   bool `toml:"deep-profiling"`

	UseStdJSON bool `toml:"use-std-json"`

	// Default values for stdhttp callers
	SkipTLSVerification bool `toml:"skip-tls-verification"`
	MinSizeForGzip      int  `toml:"min-size-for-gzip"`

	MaxWorkersCount int `toml:"max-workers-count"`
}

Common --

func GetCommon

func GetCommon() *Common

GetCommon --

func (*Common) Check

func (x *Common) Check(cfg any) (err error)

Check --

type DB

type DB struct {
	Type          string `toml:"type"`
	DSN           string `toml:"dsn"`
	MaxConnection int    `toml:"max-conn"`
	Retry         int    `toml:"retry"`
}

DB --

func (*DB) Check added in v0.1.38

func (x *DB) Check(cfg any) (err error)

----------------------------------------------------------------------------------------------------------------------------// Check --

type Duration added in v0.1.44

type Duration time.Duration

func (Duration) D added in v0.1.52

func (d Duration) D() time.Duration

func (Duration) MarshalText added in v0.1.44

func (d Duration) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (*Duration) UnmarshalText added in v0.1.44

func (d *Duration) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type Listener

type Listener struct {
	// Addr should be set to the desired listening host:port
	Addr string `toml:"bind-addr"`

	Root string `toml:"root"` // in filesystem

	ProxyPrefix string `toml:"proxy-prefix"`

	// Set certificate in order to handle HTTPS requests
	SSLCombinedPem string `toml:"ssl-combined-pem"`

	//
	Timeout Duration `toml:"timeout"`

	IconFile string `toml:"icon-file"`

	DisabledEndpointsSlice []string     `toml:"disabled-endpoints"`
	DisabledEndpoints      misc.BoolMap `toml:"-"`

	Auth Auth `toml:"auth"`
}

Listener --

func GetListener added in v0.1.55

func GetListener() *Listener

GetCommon --

func (*Listener) Check

func (x *Listener) Check(cfg any) (err error)

Check --

type User added in v0.1.33

type User struct {
	Password string
	Groups   []string
}

User --

Jump to

Keyboard shortcuts

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