loader

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Creater

type Creater interface {
	Create()
}

创建对象时调用

type JsonLoader

type JsonLoader[T any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

JsonLoader json配置加载对象 协程安全 如果T有成员函数Normalize, 会加载完配置后调用

func (*JsonLoader[T]) Get

func (l *JsonLoader[T]) Get() *T

Get 获取配置 返回的指针一定不为nil 外层不需要再判断

func (*JsonLoader[T]) GetSrc

func (l *JsonLoader[T]) GetSrc() []byte

func (*JsonLoader[T]) Load

func (l *JsonLoader[T]) Load(src []byte, path string) error

func (*JsonLoader[T]) LoadBy

func (l *JsonLoader[T]) LoadBy(t *T) error

func (*JsonLoader[T]) LoadFile

func (l *JsonLoader[T]) LoadFile(path string) error

func (*JsonLoader[T]) RegHook

func (l *JsonLoader[T]) RegHook(hook func(old, new *T))

RegHook 注册配置修改Hook

func (*JsonLoader[T]) SaveFile

func (l *JsonLoader[T]) SaveFile(path string) error

type JsonLoaders

type JsonLoaders[T any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

JsonLoaders json配置加载对象 协程安全 如果T有成员函数Normalize, 会加载完配置后调用

func (*JsonLoaders[T]) Get

func (l *JsonLoaders[T]) Get() map[string]*T

Get 返回的map对象一定不为nil 外层不需要再判断

func (*JsonLoaders[T]) GetItem

func (l *JsonLoaders[T]) GetItem(key string) *T

GetItem 获取指定的配置,返回的对象可能会为nil

func (*JsonLoaders[T]) GetSrc

func (l *JsonLoaders[T]) GetSrc() map[string][]byte

func (*JsonLoaders[T]) GetSrcItem

func (l *JsonLoaders[T]) GetSrcItem(key string) []byte

func (*JsonLoaders[T]) Load

func (l *JsonLoaders[T]) Load(src map[string][]byte, path string) error

func (*JsonLoaders[T]) RegHook

func (l *JsonLoaders[T]) RegHook(hook func(old, new map[string]*T))

RegHook 注册配置修改Hook

func (*JsonLoaders[T]) Set

func (l *JsonLoaders[T]) Set(confs map[string]*T)

不会调用Create和Normalize

type Loader

type Loader interface {
	// 获取原始配置 返回nil表示未加载
	GetSrc() []byte

	// 加载接口 src:原始配置数据 path:相关的路径
	Load(src []byte, path string) error

	// 从本地文件加载
	LoadFile(path string) error

	// 保存本地
	SaveFile(path string) error
}

ConfLoader 配置接口

type Loaders

type Loaders interface {
	// 获取原始配置 nil表示未加载过
	GetSrc() map[string][]byte

	// 获取原始配置 nil表示未加载过
	GetSrcItem(key string) []byte

	// 加载接口 src:原始配置数据 path:相关的路径
	Load(src map[string][]byte, path string) error
}

Loaders 多配置接口

type Normalizer

type Normalizer interface {
	Normalize()
}

json读取完后调用

type StrLoader

type StrLoader struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

StrLoader

func (*StrLoader) Get

func (l *StrLoader) Get() string

获取配置

func (*StrLoader) GetSrc

func (l *StrLoader) GetSrc() []byte

func (*StrLoader) Load

func (l *StrLoader) Load(src []byte, path string) error

func (*StrLoader) LoadFile

func (l *StrLoader) LoadFile(path string) error

func (*StrLoader) RegHook

func (l *StrLoader) RegHook(hook func(old, new string))

RegHook 注册配置修改Hook

func (*StrLoader) SaveFile

func (l *StrLoader) SaveFile(path string) error

Jump to

Keyboard shortcuts

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