configuration

package
v0.0.0-...-7b44a9b Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	YAML    = "yaml"
	JSON    = "json"
	UNKNOWN = ""

	LocalDriverName = "local"
	RedisDriverName = "redis"
)

Variables

View Source
var (
	ErrUnknownDriver = errors.New("the configuration driver is unknown")
)

Functions

func EnableExpandEnv

func EnableExpandEnv()

EnableExpandEnv make it can access environment variable in config content. For example:

	redis:
	  host: ${REDIS_HOST}
      port: ${REDIS_PORT:6379}

func Load

func Load(ctx context.Context, dst any) error

Load config

# load by default (local file driver): go run main.go

# load from local file driver: go run main.go -config-driver local -config config.yaml

# load from pre-registered remote driver: go run main.go -config-driver redis -config config.yaml

# load from dynamic created remote driver: go run main.go -config-driver consul -config-script consul.yaml -config app/config.yaml

func LoadWithDriver

func LoadWithDriver(ctx context.Context, driver Driver, key string, dst any) error

func LoadWithScript

func LoadWithScript(ctx context.Context, driverName, driverScript, key string, dst any) error

func SetDriver

func SetDriver(name string, d Driver)

func SetDriverBuilder

func SetDriverBuilder(name string, d DriverBuilder)

func SetFlag

func SetFlag()

func SetUnmarshaler

func SetUnmarshaler(contentType string, unmarshaler Unmarshaler)

func UnmarshalYAML

func UnmarshalYAML(data []byte, dst any) error

Types

type Driver

type Driver interface {
	Load(ctx context.Context, key string) ([]byte, string, error)
}

func NewLocalDriver

func NewLocalDriver(root string) Driver

type DriverBuilder

type DriverBuilder interface {
	Build(script string) (Driver, error)
}

func NewLocalDriverBuilder

func NewLocalDriverBuilder() DriverBuilder

type RedisDriver

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

func NewRedisDriver

func NewRedisDriver(client redis.UniversalClient, options ...RedisDriverOption) *RedisDriver

func (*RedisDriver) Load

func (d *RedisDriver) Load(ctx context.Context, key string) ([]byte, string, error)

type RedisDriverOption

type RedisDriverOption func(*RedisDriver)

func WithRedisDriverPrefix

func WithRedisDriverPrefix(prefix string) RedisDriverOption

type Unmarshaler

type Unmarshaler func([]byte, any) error

func ExpandEnvUnmarshaler

func ExpandEnvUnmarshaler(unmarshaler Unmarshaler) Unmarshaler

Jump to

Keyboard shortcuts

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