Documentation
¶
Index ¶
- Constants
- Variables
- func EnableExpandEnv()
- func Load(ctx context.Context, dst any) error
- func LoadWithDriver(ctx context.Context, driver Driver, key string, dst any) error
- func LoadWithScript(ctx context.Context, driverName, driverScript, key string, dst any) error
- func SetDriver(name string, d Driver)
- func SetDriverBuilder(name string, d DriverBuilder)
- func SetFlag()
- func SetUnmarshaler(contentType string, unmarshaler Unmarshaler)
- func UnmarshalYAML(data []byte, dst any) error
- type Driver
- type DriverBuilder
- type RedisDriver
- type RedisDriverOption
- type Unmarshaler
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 ¶
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 LoadWithScript ¶
func SetDriverBuilder ¶
func SetDriverBuilder(name string, d DriverBuilder)
func SetUnmarshaler ¶
func SetUnmarshaler(contentType string, unmarshaler Unmarshaler)
func UnmarshalYAML ¶
Types ¶
type Driver ¶
func NewLocalDriver ¶
type DriverBuilder ¶
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
type RedisDriverOption ¶
type RedisDriverOption func(*RedisDriver)
func WithRedisDriverPrefix ¶
func WithRedisDriverPrefix(prefix string) RedisDriverOption
type Unmarshaler ¶
func ExpandEnvUnmarshaler ¶
func ExpandEnvUnmarshaler(unmarshaler Unmarshaler) Unmarshaler
Click to show internal directories.
Click to hide internal directories.