config

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvNacosHost compatible with old one like:
	EnvNacosHost      = "NACOS_HOST"
	EnvNacosPort      = "NACOS_PORT"
	EnvNacosNamespace = "NACOS_NAMESPACE"
	EnvNacosGroup     = "NACOS_GROUP"
	EnvNacosDataID    = "NACOS_DATAID"

	EnvNacosLogLevel = "NACOS_LOG_LEVEL"

	EnvOtlpGrpcEndpoint = "OTLP_GRPC_ENDPOINT"

	FlagConfigFile = "config"
	FlagDumpConfig = "dump"

	DefaultLogLevel = "info"
	// DefaultLogLevelNacos oops, nacos logging debug log as info level
	DefaultLogLevelNacos = "error"
	DefaultLogEncoding   = LogEncodingJSON
	DefaultLogOutput     = "stderr"
)

Variables

View Source
var ErrEmptyConfig = errors.New("got empty config")
View Source
var ErrEmptyConfigFile = errors.New("error empty config file")
View Source
var ErrSkipProvider = errors.New("skip provider")

Functions

func DumpDemoCfg

func DumpDemoCfg(cfg interface{})

DumpDemoCfg dump the config to stdout and exit the app nolint: forbidigo

func TomlMarshalIndent

func TomlMarshalIndent(cfg interface{}) (string, error)

func TomlUnmarshaler

func TomlUnmarshaler(p []byte, v interface{}) error

func ValidateConfig

func ValidateConfig(cfg interface{}) error

Types

type Base

type Base struct {
	Tracing       bool `toml:"tracing" yaml:"tracing" json:"tracing"`                      // opentelemetry tracing
	Profile       bool `toml:"profile" yaml:"profile" json:"profile"`                      // go profiling
	Metric        bool `toml:"metric" yaml:"metric" json:"metric"`                         // prometheus metrics
	MetricGo      bool `toml:"metric_go" yaml:"metric_go" json:"metric_go"`                // prometheus go metrics
	MetricProcess bool `toml:"metric_process" yaml:"metric_process" json:"metric_process"` // prometheus process metrics

	OtlpGrpcEndpoint string `toml:"otlp_grpc_endpoint" yaml:"otlp_grpc_endpoint" json:"otlp_grpc_endpoint"`

	Log LogConfig `toml:"log" yaml:"log" json:"log"`
}

Base is the common config save your ass

func (*Base) InitOtlpGrpcEndpointFromEnv

func (b *Base) InitOtlpGrpcEndpointFromEnv()

func (*Base) LogConfig

func (b *Base) LogConfig() *LogConfig

type BaseConfigEmbedded

type BaseConfigEmbedded interface {
	InitOtlpGrpcEndpointFromEnv()
}

type BeforeInspectHook

type BeforeInspectHook func(config interface{})

type ChangeListener

type ChangeListener func(namespace, group, dataId, data string)

type ConfigLoader

type ConfigLoader struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *ConfigLoader

func (*ConfigLoader) Load

func (cl *ConfigLoader) Load(cfg interface{}) error

type FileProvider

type FileProvider struct {
	DefaultConfigPath     string
	SkipIfPathEmpty       bool // skip this provider if config file path is empty
	SkipIfDefaultNotExist bool
}

func (*FileProvider) Config

func (p *FileProvider) Config(helper *providerHelper) ([]byte, error)

func (*FileProvider) Name

func (p *FileProvider) Name() string

type FlagParseResult

type FlagParseResult interface {
	ConfigFile() string
	DumpConfig() bool
	ShowHelp() bool
	ShowVersion() bool
	Usage() func()
}

type FlagParser

type FlagParser func() FlagParseResult

type FlagSet

type FlagSet = pflag.FlagSet

type GoRedisConfig

type GoRedisConfig struct {
	URI     string `toml:"uri" json:"uri" yaml:"uri" validate:"uri" long:"uri" description:"redis server uri"`
	Tracing bool   `toml:"tracing" json:"tracing" yaml:"tracing"`
}

type InspectConfig

type InspectConfig func(config interface{}) error

type LogConfig

type LogConfig struct {
	// Level set log level, can be empty, or one of debug|info|warn|error|fatal|panic
	Level string `toml:"level" json:"level" yaml:"level"`
	// Output set output file path, can be filepath or stdout|stderr
	Output string `toml:"output" json:"output" yaml:"output"`
	// Encoding sets the logger's encoding. Valid values are "json" and "console". default: json
	Encoding LogEncoding `toml:"encoding" json:"encoding" yaml:"encoding"`
	// enable stacktrace
	DisableStacktrace bool `toml:"disable_stacktrace" json:"disable_stacktrace" yaml:"disable_stacktrace"`
}

func (*LogConfig) GetDisableStacktrace

func (l *LogConfig) GetDisableStacktrace() bool

func (*LogConfig) GetEncoding

func (l *LogConfig) GetEncoding() string

func (*LogConfig) GetInitialFields

func (l *LogConfig) GetInitialFields() map[string]interface{}

func (*LogConfig) GetLevel

func (l *LogConfig) GetLevel() string

func (*LogConfig) GetOutput

func (l *LogConfig) GetOutput() string

type LogEncoding

type LogEncoding string
const (
	LogEncodingJSON    LogEncoding = "json"
	LogEncodingConsole LogEncoding = "console"
)

the default is json, if not empty, must be one of: console|json

type Logger

type Logger interface {
	// nolint: gofumpt
	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})
}

Logger is the interface that wraps the basic Log methods for usage only in the config init stage

type LoggerConfig

type LoggerConfig interface {
	GetLevel() string
	GetOutput() string
	GetEncoding() string
	GetDisableStacktrace() bool
	GetInitialFields() map[string]interface{}
}

type MongoConfig

type MongoConfig struct {
	DB string `toml:"db" json:"db" yaml:"db" validate:"required"`
	// URI https://www.mongodb.com/docs/manual/reference/connection-string/
	URI     string `toml:"uri" yaml:"uri" json:"uri" validate:"required"`
	Tracing bool   `toml:"tracing" json:"tracing" long:"tracing" yaml:"tracing" description:"enable tracing middleware"`
}

type MysqlConfig

type MysqlConfig struct {
	Dsn          string `toml:"dsn" yaml:"dsn" json:"dsn" validate:"required"` // data source name
	MaxOpenCount int    `toml:"max_open_count" json:"max_open_count" validate:"required" yaml:"max_open_count"`
	MaxIdleCount int    `toml:"max_idle_count" json:"max_idle_count" validate:"required" yaml:"max_idle_count"`
	Tracing      bool   `toml:"tracing" json:"tracing" yaml:"tracing"`
}

type NacosClient

type NacosClient struct {
	// contains filtered or unexported fields
}

type NacosProvider

type NacosProvider struct {
	ChangeListener ChangeListener
	NacosLogger    nacosLogger.Logger // custom logger for replacing nacos default logger
	LogLevel       string             // log level for nacos default logger
}

func (*NacosProvider) Config

func (p *NacosProvider) Config(helper *providerHelper) ([]byte, error)

func (*NacosProvider) Name

func (p *NacosProvider) Name() string

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithBeforeInspectHook

func WithBeforeInspectHook(opt BeforeInspectHook) Option

func WithCustomUnmarshaler

func WithCustomUnmarshaler(opt Unmarshaler) Option

func WithDumpMarshalledConfig

func WithDumpMarshalledConfig(opt bool) Option

func WithFlagParser

func WithFlagParser(opt FlagParser) Option

func WithInspectConfig

func WithInspectConfig(opt InspectConfig) Option

func WithLogger

func WithLogger(opt Logger) Option

WithLogger init the logger config for infra.config package, before app start the name ref to "Early KMS start"

func WithProviders

func WithProviders(opt ...Provider) Option

func WithRegisterFlags

func WithRegisterFlags(opt RegisterFlags) Option

WithRegisterFlags is used for add extra cli flags before parse args

func WithServiceName

func WithServiceName(opt string) Option

func WithServiceVersion

func WithServiceVersion(opt string) Option

func WithShortDescription

func WithShortDescription(opt string) Option

func WithUsage

func WithUsage(opt string) Option

type Provider

type Provider interface {
	Name() string
	Config(*providerHelper) ([]byte, error)
}

type RegisterFlags

type RegisterFlags func(flag *FlagSet)

type TextProvider

type TextProvider struct {
	ConfigText []byte
}

func (*TextProvider) Config

func (p *TextProvider) Config(helper *providerHelper) ([]byte, error)

func (*TextProvider) Name

func (p *TextProvider) Name() string

type Unmarshaler

type Unmarshaler func(p []byte, v interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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