config

package
v0.0.0-...-3b1ec4e Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	YAML = DecoderType(iota)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config interface {
	// if not found return default value
	Read(key, defaultValue string) string

	ReadInt(key string, defaultValue int) int

	ReadBool(key string, defaultValue bool) bool
}

read config file

type Decoder

type Decoder interface {
	// decode data into val, val should be pointer
	Decode(data []byte) (Config, error)
}

type DecoderType

type DecoderType int

type Event

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

type EventType

type EventType int
const (
	Update EventType = iota
	Delete
)

type FileSystemProvider

type FileSystemProvider struct {
}

func (*FileSystemProvider) Load

func (r *FileSystemProvider) Load(ctx context.Context, fp string) ([]byte, error)

func (*FileSystemProvider) Name

func (p *FileSystemProvider) Name() string

func (*FileSystemProvider) Watch

func (r *FileSystemProvider) Watch(ctx context.Context, fp string) (<-chan Event, error)

type Loader

type Loader interface {
	Load(ctx context.Context, fp string, opts ...Option) (Config, error)
}

load the config, it may internally uses Provider to read config

func NewLoader

func NewLoader(ctx context.Context, opts ...Option) (Loader, error)

type Option

type Option func(*options)

func WithDecoder

func WithDecoder(v Decoder) Option

func WithProvider

func WithProvider(v Provider) Option

func WithReload

func WithReload(v bool) Option

type Provider

type Provider interface {
	Watcher
	Name() string
	Load(ctx context.Context, fp string) ([]byte, error)
}

type ProviderType

type ProviderType string
const (
	ProviderGFileSystem ProviderType = "fs"
)

type Watcher

type Watcher interface {
	Watch(ctx context.Context, fp string) (<-chan Event, error)
}

watch file changes

type YAMLConfig

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

func NewYamlConfig

func NewYamlConfig(fp string) (*YAMLConfig, error)

func (*YAMLConfig) Read

func (r *YAMLConfig) Read(key, defaultValue string) string

func (*YAMLConfig) ReadBool

func (r *YAMLConfig) ReadBool(key string, defaultValue bool) bool

func (*YAMLConfig) ReadInt

func (r *YAMLConfig) ReadInt(key string, defaultValue int) int

type YAMLDecoder

type YAMLDecoder struct{}

func (*YAMLDecoder) Decode

func (r *YAMLDecoder) Decode(data []byte) (Config, error)

Jump to

Keyboard shortcuts

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