config

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyDir = errors.New("empty directory")

Functions

func ContextWithLogger added in v1.0.0

func ContextWithLogger(ctx context.Context, logger *slog.Logger) context.Context

set logger as context value

func LoggerFromContext added in v1.0.0

func LoggerFromContext(ctx context.Context) (*slog.Logger, bool)

extract logger from context

Types

type Config

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

func New

func New(ctx context.Context, options Options) (cfg *Config, err error)

Creates new config instance. Provide Options object to set config path and etc. If configuration directory is empty the ErrEmptyDir sentinel error will be returned.

func (*Config) Get

func (c *Config) Get(ctx context.Context, path string, files ...string) (any, bool)

Get method takes dot delimited configuration path and returns value if any. The last parameter specifies which files to allow for searching both with or without extension. If omitted, all files will be search through. The sequence of transmitted files does not change the original order for searching. Second returned value states if it was found and follows comma ok idiom at all.

func (*Config) GetVaultClient added in v1.0.0

func (c *Config) GetVaultClient() *vault.Client

Return created or directly passed vault client

func (*Config) MustGet added in v1.0.0

func (c *Config) MustGet(ctx context.Context, path string, files ...string) any

MustGet method is the same as Get except that it panics if the path does not exist

type Options

type Options struct {
	Directory   string
	FileSystem  fs.ReadDirFS
	Instance    string
	Deployment  string
	Hostname    string
	Logger      *slog.Logger
	VaultClient *vault.Client
	VaultAuth   vault.AuthMethod
}

Config options:

  • Directory: path to config files. May be multiple directories delimited by os specific path separator

  • FileSystem: an interface that provides access to some point in the file system. The directory path will be considered relative if it is non nil. It can be useful when the configuration is embedded

  • Instance: is concrete instance number in multi instance deployments

  • Deployment: is concrete deployment. For example "production" or "development"

  • Hostname: mean current machine hostname

  • Logger: produce output to supplied logger. Module will be silent if nil was received.

  • VaultClient: vault client if you don't want to create a new one

  • VaultAuth: is AuthMethod interface from vault api module that provides Login method

type VaultConfigAuthType added in v1.0.0

type VaultConfigAuthType int

Jump to

Keyboard shortcuts

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