Documentation
¶
Index ¶
- Variables
- func GetNodeEnvPrefix(node EntryPointInterface) string
- func GetNodeProg(node EntryPointInterface) string
- func GetNodeProgList(node EntryPointInterface) []string
- func ReflectFieldName(f reflect.StructField) string
- func RegistSubNode(parent, child EntryPointInterface)
- func WithConfig(conf *EntryPointMeta) optparams.Option[EntryPointMeta]
- func WithDefaultConfigFilePaths(paths ...string) optparams.Option[EntryPointMeta]
- func WithDescription(desc string) optparams.Option[EntryPointMeta]
- func WithEnvPrefix(prefix string) optparams.Option[EntryPointMeta]
- func WithLoadAllConfigFile() optparams.Option[EntryPointMeta]
- func WithName(name string) optparams.Option[EntryPointMeta]
- func WithNotParseEnv() optparams.Option[EntryPointMeta]
- func WithNotVerifySchema() optparams.Option[EntryPointMeta]
- func WithUsage(usage string) optparams.Option[EntryPointMeta]
- func WithWatchMode() optparams.Option[EntryPointMeta]
- type EndPoint
- func (ep *EndPoint[T]) BeforeRefresh(callback func([]byte, SupportedSerialization) bool) error
- func (ep *EndPoint[T]) GenEtcdWatcher(serialize_protocol SupportedSerialization, filepath string, ...) (StopWatchFunc, error)
- func (ep *EndPoint[T]) GenFSWatcher(serialize_protocol SupportedSerialization, filepath string, indocker bool) (StopWatchFunc, error)
- func (ep *EndPoint[T]) IsEndpoint() bool
- func (ep *EndPoint[T]) IsRoot() bool
- func (ep *EndPoint[T]) Meta() *EntryPointMeta
- func (ep *EndPoint[T]) OnRefresh(callback func(T)) error
- func (ep *EndPoint[T]) OnRefreshError(callback func(error)) error
- func (ep *EndPoint[T]) Parse(argv []string)
- func (ep *EndPoint[T]) Schema() []byte
- func (ep *EndPoint[T]) SetChild(child EntryPointInterface) error
- func (ep *EndPoint[T]) SetParent(parent EntryPointInterface) EntryPointInterface
- type EndPointConfigInterface
- type EntryPoint
- func (ep *EntryPoint) IsEndpoint() bool
- func (ep *EntryPoint) IsRoot() bool
- func (ep *EntryPoint) Meta() *EntryPointMeta
- func (ep *EntryPoint) Parse(argv []string)
- func (ep *EntryPoint) Schema() []byte
- func (ep *EntryPoint) SetChild(child EntryPointInterface) error
- func (ep *EntryPoint) SetParent(parent EntryPointInterface) EntryPointInterface
- type EntryPointInterface
- type EntryPointMeta
- func (ep *EntryPointMeta) IsEndpoint() bool
- func (ep *EntryPointMeta) IsRoot() bool
- func (ep *EntryPointMeta) Meta() *EntryPointMeta
- func (ep *EntryPointMeta) Parent() EntryPointInterface
- func (ep *EntryPointMeta) SetChild(child EntryPointInterface)
- func (ep *EntryPointMeta) SetParent(parent EntryPointInterface)
- func (ep *EntryPointMeta) Subcmds() map[string]EntryPointInterface
- type StopWatchFunc
- type SupportedSerialization
Constants ¶
This section is empty.
Variables ¶
var ( //ErrNotAllowSetChildToEndPoint 叶子节点无法设置子节点 ErrNotAllowSetChildToEndPoint = errors.New("not allow set child to endpoint") //ErrUnsupportedSchema 不支持的的schema类型 ErrUnsupportedSchema = errors.New("unsupported schema") //ErrReregistCallBack 重复注册回调函数 ErrReregistCallBack = errors.New("not allow re-regist callback") //ErrUnsupportedSerialization 不支持的序列化协议 ErrUnsupportedSerialization = errors.New("unsupported serialization protocol") //ErrNotSetSerialize 未设置序列化协议 ErrNotSetSerialize = errors.New("need to set serialize") //ErrEtcdKeyLenNotMatch etcd的key数量不匹配 ErrEtcdKeyLenNotMatch = errors.New("etcd key len not match") )
Functions ¶
func GetNodeEnvPrefix ¶
func GetNodeEnvPrefix(node EntryPointInterface) string
GetNodeEnvPrefix 获取实际的EnvPrefix
func GetNodeProgList ¶
func GetNodeProgList(node EntryPointInterface) []string
GetNodeProgList 获取节点的prog值
func ReflectFieldName ¶
func ReflectFieldName(f reflect.StructField) string
ReflectFieldInfo 返回字段的基础信息 @returns string 对应名字
func RegistSubNode ¶
func RegistSubNode(parent, child EntryPointInterface)
RegistSubNode 将一对节点互设为父子节点 @params parent EntryPointInterface 父节点 @params child EntryPointInterface 子节点
func WithConfig ¶
func WithConfig(conf *EntryPointMeta) optparams.Option[EntryPointMeta]
WithConfig 使用EntryPointMeta实例设置配置
func WithDefaultConfigFilePaths ¶
func WithDefaultConfigFilePaths(paths ...string) optparams.Option[EntryPointMeta]
WithDefaultConfigFilePaths 设置节点用法说明
func WithDescription ¶
func WithDescription(desc string) optparams.Option[EntryPointMeta]
WithDescription 设置节点说明文本
func WithEnvPrefix ¶
func WithEnvPrefix(prefix string) optparams.Option[EntryPointMeta]
WithEnvPrefix 设置节点用法说明
func WithLoadAllConfigFile ¶
func WithLoadAllConfigFile() optparams.Option[EntryPointMeta]
WithLoadAllConfigFile 设置节点是加载全部配置文件,否则找到第一个后就停止搜索
func WithNotParseEnv ¶
func WithNotParseEnv() optparams.Option[EntryPointMeta]
WithNotParseEnv 设置节点不解析环境变量
func WithNotVerifySchema ¶
func WithNotVerifySchema() optparams.Option[EntryPointMeta]
WithNotVerifySchema 设置节点不校验配置的schema
func WithWatchMode ¶
func WithWatchMode() optparams.Option[EntryPointMeta]
WithWatchMode 设置监听模式 在程序执行过程中监听`-c`(或`--config`)指定的配置文件url内容变更. 当出现变更时更新`EndPoint[T]`对象中的config对象,并根据其中的回调函数设置执行相应回调
Types ¶
type EndPoint ¶
type EndPoint[T EndPointConfigInterface] struct { // contains filtered or unexported fields }
EntryPoint 节点类 @generics T EndPointConfigInterface 内部`config`字段的类型
func NewEndPoint ¶
func NewEndPoint[T EndPointConfigInterface](config T, opts ...optparams.Option[EntryPointMeta]) (*EndPoint[T], error)
NewEndPoint创建一个节点对象 @generics T EndPointConfigInterface EntryPoint泛型的实例化参数 @params meta *EntryPointMeta 为节点的元信息
func (*EndPoint[T]) BeforeRefresh ¶
func (ep *EndPoint[T]) BeforeRefresh(callback func([]byte, SupportedSerialization) bool) error
BeforeRefresh 注册刷新前执行 @generics T EndPointConfigInterface 内部`config`字段的类型 @params callback func([]byte, SupportedSerialization) bool 刷新前执行的函数,返回false则不会进行刷新
func (*EndPoint[T]) GenEtcdWatcher ¶ added in v2.1.0
func (ep *EndPoint[T]) GenEtcdWatcher(serialize_protocol SupportedSerialization, filepath string, config clientv3.Config) (StopWatchFunc, error)
GenEtcdWatcher 生成文件系统监听器 @generics T EndPointConfigInterface 内部`config`字段的类型 @params serialize_protocol SupportedSerialization 文件使用的序列化协议 @params filepath string 文件路径 @params config clientv3.Config etcd配置 @returns StopWatchFunc 停止监听函数 @returns error 程序错误
func (*EndPoint[T]) GenFSWatcher ¶ added in v2.1.0
func (ep *EndPoint[T]) GenFSWatcher(serialize_protocol SupportedSerialization, filepath string, indocker bool) (StopWatchFunc, error)
GenFSWatcher 生成文件系统监听器 @generics T EndPointConfigInterface 内部`config`字段的类型 @params serialize_protocol SupportedSerialization 使用的序列化协议 @params filepath string 文件路径 @params indocker bool 文件系统是否在docker中 @returns StopWatchFunc 停止监听函数 @returns error 程序错误
func (*EndPoint[T]) IsEndpoint ¶
func (*EndPoint[T]) Meta ¶
func (ep *EndPoint[T]) Meta() *EntryPointMeta
func (*EndPoint[T]) OnRefresh ¶
BeforeRefresh 注册刷新前执行 @generics T EndPointConfigInterface 内部`config`字段的类型 @params callback func(T) bool 注册刷新后执行的操作
func (*EndPoint[T]) OnRefreshError ¶
OnRefreshError 注册刷新失败后执行的回调 @generics T EndPointConfigInterface 内部`config`字段的类型 @params callback func(T) bool 注册刷新失败后执行的回调
func (*EndPoint[T]) SetChild ¶
func (ep *EndPoint[T]) SetChild(child EntryPointInterface) error
func (*EndPoint[T]) SetParent ¶
func (ep *EndPoint[T]) SetParent(parent EntryPointInterface) EntryPointInterface
type EndPointConfigInterface ¶
type EndPointConfigInterface interface {
Main() //进入时执行的程序
}
EndPointConfigInterface 叶子节点配置接口
type EntryPoint ¶
type EntryPoint struct {
// contains filtered or unexported fields
}
EntryPoint 节点类
func NewEntryPoint ¶
func NewEntryPoint(opts ...optparams.Option[EntryPointMeta]) (*EntryPoint, error)
New 创建一个节点对象 @params meta *EntryPointMeta 为节点的元信息
func (*EntryPoint) IsEndpoint ¶
func (ep *EntryPoint) IsEndpoint() bool
func (*EntryPoint) IsRoot ¶
func (ep *EntryPoint) IsRoot() bool
func (*EntryPoint) Meta ¶
func (ep *EntryPoint) Meta() *EntryPointMeta
func (*EntryPoint) Schema ¶
func (ep *EntryPoint) Schema() []byte
func (*EntryPoint) SetChild ¶
func (ep *EntryPoint) SetChild(child EntryPointInterface) error
func (*EntryPoint) SetParent ¶
func (ep *EntryPoint) SetParent(parent EntryPointInterface) EntryPointInterface
type EntryPointInterface ¶
type EntryPointInterface interface { Meta() *EntryPointMeta Schema() []byte IsRoot() bool IsEndpoint() bool SetChild(EntryPointInterface) error SetParent(EntryPointInterface) EntryPointInterface Parse([]string) }
type EntryPointMeta ¶
type EntryPointMeta struct { Name string //节点名 Description string //节点简介 Usage string //节点用法介绍 DefaultConfigFilePaths []string //节点执行的默认配置文件路径列表 LoadAllConfigFile bool //是否加载全部配置文件,否则找到第一个后就停止搜索 NotParseEnv bool //是否不解析环境变量 EnvPrefix string //解析环境变量时的前缀 NotVerifySchema bool //是否不校验配置的schema // DebugMode bool //当设置为debugmode时才会打印中间过程的log WatchMode bool //启用配置监听模式, // contains filtered or unexported fields }
EntryPointMeta 节点的元数据类
func (*EntryPointMeta) IsEndpoint ¶
func (ep *EntryPointMeta) IsEndpoint() bool
IsEndpoint 判断节点是否为叶子节点
func (*EntryPointMeta) Parent ¶
func (ep *EntryPointMeta) Parent() EntryPointInterface
func (*EntryPointMeta) SetChild ¶
func (ep *EntryPointMeta) SetChild(child EntryPointInterface)
SetChild 为节点设置子节点 @Params child EntryPointInterface 要作为子节点的节点
func (*EntryPointMeta) SetParent ¶
func (ep *EntryPointMeta) SetParent(parent EntryPointInterface)
SetParent 为节点设置父节点 @Params parent EntryPointInterface 要作为父节点的节点
func (*EntryPointMeta) Subcmds ¶
func (ep *EntryPointMeta) Subcmds() map[string]EntryPointInterface
type StopWatchFunc ¶
type StopWatchFunc func()
type SupportedSerialization ¶
type SupportedSerialization int8
const ( SerializationJSON SupportedSerialization = iota SerializationYAML )
func ParseEtcdUrl ¶ added in v2.1.0
func ParseEtcdUrl(U *url.URL) (SupportedSerialization, string, clientv3.Config, time.Duration, error)
ParseEtcdUrl 解析Etcd的URL @params U *url.URL url信息 @returns SupportedSerialization 序列化协议 @returns string 路径,即key @returns clientv3.Config etcd连接配置 @returns time.Duration etcd请求超时 @returns error 解析错误
func ParseFSPath ¶ added in v2.1.0
func ParseFSPath(path string) (SupportedSerialization, string, error)
ParseFSUrl 解析文件系统的URL @params U *url.URL url信息 @returns SupportedSerialization 序列化协议 @returns string 路径 @returns error 解析错误
func ParseFSUrl ¶ added in v2.1.0
func ParseFSUrl(U *url.URL) (SupportedSerialization, string, error)
ParseFSUrl 解析文件系统的URL @params U *url.URL url信息 @returns SupportedSerialization 序列化协议 @returns string 路径 @returns error 解析错误