confx

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultLoadFunc = func(kvs []*mvccpb.KeyValue, target any) {
		data := kvs[0].Value
		if err := conf.LoadFromYamlBytes(data, target); err != nil {
			log.Panicf("load and parse config from etcd fail err = %v", err)
		}
	}
	DefaultWatchOnConfigChange = func(evs []*clientv3.Event, target any) {

		for _, ev := range evs {

			logx.Sloww(" config  has changed", logx.Field("data", string(ev.Kv.Value)))
			if err := conf.LoadFromYamlBytes(ev.Kv.Value, target); err != nil {
				logx.Errorw("load and parse config from etcd fail err = %v", logger.ErrorField(err))
			}
		}

	}
)

Functions

func MustLoadFromEtcd

func MustLoadFromEtcd(key string, etcdConfig etcd.EtcdConfig, target any, ops ...ConfigCustomFuncOption)

MustLoadFromEtcd 从etcd中加载配置,有状态的服务从etcd中获取

func WatchConfig

func WatchConfig(key string, target any, cli *clientv3.Client, f func(evs []*clientv3.Event, target any))

Types

type ConfigCustomFuncOption

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

func WithCustomInitLoadFunc

func WithCustomInitLoadFunc(f func(kvs []*mvccpb.KeyValue, target any)) ConfigCustomFuncOption

func WithCustomWatchFunc

func WithCustomWatchFunc(f func(evs []*clientv3.Event, target any)) ConfigCustomFuncOption

func WithDefaultInitLoadFunc

func WithDefaultInitLoadFunc() ConfigCustomFuncOption

type ConfigPrefix

type ConfigPrefix string
const (
	Prefix              = "config"
	Kline  ConfigPrefix = "kline"
	Ticker ConfigPrefix = "ticker"
	Match  ConfigPrefix = "match"
	Order  ConfigPrefix = "order"
)

func (ConfigPrefix) BuildKey

func (c ConfigPrefix) BuildKey(symbol string) string

type Op

type Op int8
const (
	InitLoad Op = iota + 1
	WatchChange
)

Jump to

Keyboard shortcuts

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