cfgmgr

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config[T any] struct {
	// contains filtered or unexported fields
}

func (*Config[T]) Get

func (c *Config[T]) Get() *T

func (*Config[T]) Set

func (c *Config[T]) Set(t *T)

type ConfigManager

type ConfigManager struct {
	Etcd *etcd.Etcd

	Watcher Watcher
	// contains filtered or unexported fields
}

func New

func New(w Watcher) *ConfigManager

func (*ConfigManager) Close

func (m *ConfigManager) Close()

func (*ConfigManager) GetErr

func (m *ConfigManager) GetErr(file, md5 string) string

func (*ConfigManager) Load

func (m *ConfigManager) Load(file string)

func (*ConfigManager) LoadAll

func (m *ConfigManager) LoadAll()

func (*ConfigManager) Start

func (m *ConfigManager) Start()

func (*ConfigManager) Watch

func (m *ConfigManager) Watch(file string, f LoadFunc)

func (*ConfigManager) WatchAndLoad

func (m *ConfigManager) WatchAndLoad(file string, f LoadFunc)

func (*ConfigManager) WatchPrefix

func (m *ConfigManager) WatchPrefix(file string, f LoadFuncWithName)

type EtcdWatcher

type EtcdWatcher struct {
	Etcd *etcd.Etcd
	// contains filtered or unexported fields
}

func NewEtcdWatcher

func NewEtcdWatcher(et *etcd.Etcd) *EtcdWatcher

func (*EtcdWatcher) GetFileNames

func (m *EtcdWatcher) GetFileNames() ([]string, error)

func (*EtcdWatcher) Init

func (m *EtcdWatcher) Init() error

func (*EtcdWatcher) IsExists

func (m *EtcdWatcher) IsExists(name string) bool

func (*EtcdWatcher) ReadFile

func (m *EtcdWatcher) ReadFile(name string) ([]byte, error)

func (*EtcdWatcher) Start

func (m *EtcdWatcher) Start(closeCh chan struct{}, dispatch func(string, []byte))

func (*EtcdWatcher) Stop

func (m *EtcdWatcher) Stop() error

func (*EtcdWatcher) WriteFile

func (m *EtcdWatcher) WriteFile(name string, content []byte) error

type FileWatcher

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

func NewFileWatcher

func NewFileWatcher(path string) *FileWatcher

func (*FileWatcher) GetFileNames

func (m *FileWatcher) GetFileNames() (ret []string, err error)

func (*FileWatcher) Init

func (m *FileWatcher) Init() error

func (*FileWatcher) IsExists

func (m *FileWatcher) IsExists(name string) bool

func (*FileWatcher) ReadFile

func (m *FileWatcher) ReadFile(name string) ([]byte, error)

func (*FileWatcher) Start

func (m *FileWatcher) Start(closeCh chan struct{}, dispatch func(string, []byte))

func (*FileWatcher) Stop

func (m *FileWatcher) Stop() error

func (*FileWatcher) WriteFile

func (m *FileWatcher) WriteFile(name string, content []byte) error

type LoadData

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

func (*LoadData) IsMatch

func (d *LoadData) IsMatch(file string) bool

type LoadFunc

type LoadFunc func(buf []byte) error

func AtomicLoad

func AtomicLoad[T any](dest *Config[T], unmarshalFn unmarshaler) LoadFunc

xxconfig := Config[T]{} ConfigManager.Watch("config.json", AtomicLoad(&xxconfig, json.Unmarshal)) cfg := xxconfig.Get()

type LoadFuncWithName

type LoadFuncWithName func(file string, buf []byte) error

type Watcher

type Watcher interface {
	Init() error
	Start(closeCh chan struct{}, dispatch func(string, []byte))
	Stop() error
	GetFileNames() ([]string, error)
	ReadFile(name string) ([]byte, error)
	WriteFile(name string, content []byte) error
	IsExists(name string) bool
}

Jump to

Keyboard shortcuts

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