Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func DeleteLogger(configKey string) error
- func DeleteWriter(configKey string) error
- func DevelopMode() error
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Fatal(v ...interface{})
- func Fatalf(format string, v ...interface{})
- func GetWriter(configKey string) io.Writer
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func LoadConfig(configKey string, config Config) error
- func Panic(v ...interface{})
- func Panicf(format string, v ...interface{})
- func Run(ctx context.Context, param Parameter) (err error)
- func SetAllConfigBytes(data []byte, configType ConfigType) (err error)
- func SetConfig(configKey string, config Config) error
- func SetConfigPath(confPath string) error
- func SetLogger(configKey string, logger Logger) error
- func SetWriter(configKey string, w io.Writer) error
- func Warn(v ...interface{})
- func Warnf(format string, v ...interface{})
- type Banner
- type BaseFactory
- func (f *BaseFactory[T]) Close(name string) error
- func (f *BaseFactory[T]) CloseAll() error
- func (f *BaseFactory[T]) Count() int
- func (f *BaseFactory[T]) Get(name string) (T, error)
- func (f *BaseFactory[T]) Has(name string) bool
- func (f *BaseFactory[T]) Names() []string
- func (f *BaseFactory[T]) Register(name string, instance T) error
- func (f *BaseFactory[T]) RegisterWithCloser(name string, instance T, closer func() error) error
- type BaseMultiConfig
- func (b *BaseMultiConfig[C]) GetDefaultInstanceName() string
- func (b *BaseMultiConfig[C]) GetInstanceByName(name string) (C, bool)
- func (b *BaseMultiConfig[C]) GetInstances() []Instance[C]
- func (b *BaseMultiConfig[C]) MarshalJSON() ([]byte, error)
- func (b *BaseMultiConfig[C]) SetDefaultInstanceName(name string)
- func (b *BaseMultiConfig[C]) SetInstances(instances []Instance[C])
- type Config
- type ConfigType
- type ErrorTao
- type ErrorUnWrapper
- type Factory
- type Instance
- type Log
- type LogFlag
- type LogLevel
- type LogType
- type Logger
- type MultiConfig
- type Parameter
- type PipeTask
- type Pipeline
- type PipelineOption
- type Task
- type TaskOption
- type TaskRun
- type TaskState
- type Universe
Constants ¶
const ( Unknown = "Unknown" ParamInvalid = "ParamInvalid" ContextCanceled = "ContextCanceled" DuplicateCall = "DuplicateCall" TaskRunError = "TaskRunError" TaskRunTwice = "TaskRunTwice" TaskCloseTwice = "TaskCloseTwice" TaskClosed = "TaskClosed" TaskRunning = "TaskRunning" ConfigNotFound = "ConfigNotFound" UniverseNotInit = "UniverseNotInit" InstancesNotClosed = "InstancesNotClosed" )
ErrorCode
const ConfigKey = "tao"
ConfigKey for this repo
const DefaultInstanceKey = "default"
DefaultInstanceKey is the default instance name for single-instance configs
Variables ¶
var Add = tao.Add
Add of tao
var Done = tao.Done
Done of tao
var UniverseInitTimeout = time.Minute
UniverseInitTimeout is the timeout for universe initialization. Default is 1 minute. Can be changed before calling tao.Run().
Functions ¶
func DevelopMode ¶ added in v0.0.4
func DevelopMode() error
DevelopMode called to enable default configs for all
func LoadConfig ¶ added in v0.1.5
LoadConfig by key of config
func SetAllConfigBytes ¶ added in v0.1.4
func SetAllConfigBytes(data []byte, configType ConfigType) (err error)
SetAllConfigBytes from config file or code
func SetConfigPath ¶ added in v0.0.4
SetConfigPath in your project's init()
Types ¶
type BaseFactory ¶ added in v0.2.0
type BaseFactory[T any] struct { // contains filtered or unexported fields }
BaseFactory 工厂基础实现
func NewBaseFactory ¶ added in v0.2.0
func NewBaseFactory[T any]() *BaseFactory[T]
NewBaseFactory creates a new BaseFactory instance
func Register ¶ added in v0.0.4
func Register[T any, C any]( configKey string, config MultiConfig[C], constructor func(name string, cfg C) (T, func() error, error), ) (*BaseFactory[T], error)
Register unit to tao universe.
Generic factory pattern registration with MultiConfig:
- Parses multi-instance config (single-instance config is auto-wrapped as {default: config})
- Calls constructor for each instance
func (*BaseFactory[T]) Close ¶ added in v0.2.0
func (f *BaseFactory[T]) Close(name string) error
func (*BaseFactory[T]) CloseAll ¶ added in v0.2.0
func (f *BaseFactory[T]) CloseAll() error
func (*BaseFactory[T]) Count ¶ added in v0.2.0
func (f *BaseFactory[T]) Count() int
func (*BaseFactory[T]) Get ¶ added in v0.2.0
func (f *BaseFactory[T]) Get(name string) (T, error)
func (*BaseFactory[T]) Has ¶ added in v0.2.0
func (f *BaseFactory[T]) Has(name string) bool
func (*BaseFactory[T]) Names ¶ added in v0.2.0
func (f *BaseFactory[T]) Names() []string
func (*BaseFactory[T]) Register ¶ added in v0.2.0
func (f *BaseFactory[T]) Register(name string, instance T) error
func (*BaseFactory[T]) RegisterWithCloser ¶ added in v0.2.0
func (f *BaseFactory[T]) RegisterWithCloser(name string, instance T, closer func() error) error
type BaseMultiConfig ¶ added in v0.2.0
type BaseMultiConfig[C any] struct { Instances []Instance[C] `json:"-" yaml:"-"` Default string `json:"default_instance" yaml:"default_instance"` }
BaseMultiConfig 多实例配置基础实现
func (*BaseMultiConfig[C]) GetDefaultInstanceName ¶ added in v0.2.0
func (b *BaseMultiConfig[C]) GetDefaultInstanceName() string
GetDefaultInstanceName returns the default instance name
func (*BaseMultiConfig[C]) GetInstanceByName ¶ added in v0.2.1
func (b *BaseMultiConfig[C]) GetInstanceByName(name string) (C, bool)
GetInstanceByName returns the instance config by name
func (*BaseMultiConfig[C]) GetInstances ¶ added in v0.2.0
func (b *BaseMultiConfig[C]) GetInstances() []Instance[C]
GetInstances returns the instances slice
func (*BaseMultiConfig[C]) MarshalJSON ¶ added in v0.2.0
func (b *BaseMultiConfig[C]) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler to restore original config file structure. - Single instance (only "default" key): outputs flat config for easy editing - Multi-instance: outputs named instance keys with default_instance field Includes ValidSelf supplemented defaults
func (*BaseMultiConfig[C]) SetDefaultInstanceName ¶ added in v0.2.0
func (b *BaseMultiConfig[C]) SetDefaultInstanceName(name string)
SetDefaultInstanceName sets the default instance name
func (*BaseMultiConfig[C]) SetInstances ¶ added in v0.2.0
func (b *BaseMultiConfig[C]) SetInstances(instances []Instance[C])
SetInstances sets the instances slice
type Config ¶
type Config interface {
// Name of Config
Name() string
// ValidSelf with some default values
ValidSelf()
// ToTask transform itself to Task
ToTask() Task
// RunAfter defines pre task names
RunAfter() []string
}
Config interface
type ConfigType ¶ added in v0.0.2
type ConfigType uint8
ConfigType of config file
const ( // None of config None ConfigType = iota // Yaml config Yaml // JSON config JSON )
type ErrorUnWrapper ¶
ErrorUnWrapper describe error which can be unwrapped
func NewErrorWrapped ¶ added in v0.0.3
func NewErrorWrapped(format string, e error) ErrorUnWrapper
NewErrorWrapped constructor of errorWrapped
type Factory ¶ added in v0.2.0
type Factory[T any] interface { Get(name string) (T, error) Has(name string) bool Names() []string }
Factory 通用工厂接口
type Log ¶ added in v0.0.2
type Log struct {
Level LogLevel `json:"level"`
Type LogType `json:"type"`
Flag LogFlag `json:"flag"`
CallDepth int `json:"call_depth"`
Path string `json:"path,omitempty"`
Disable bool `json:"disable"`
}
Log config in tao
type LogFlag ¶ added in v0.1.4
type LogFlag int
LogFlag log's flag
func (LogFlag) MarshalText ¶ added in v0.1.4
MarshalText instead of number
func (*LogFlag) UnmarshalText ¶ added in v0.1.4
UnmarshalText to number
type LogLevel ¶
type LogLevel uint8
LogLevel log's level
const ( // DEBUG (usually) is used in development env to print track info but disabled in production env to avoid overweight logs DEBUG LogLevel = iota // INFO (usually) is default level to print some core infos INFO // WARNING should be mentioned, it's more important than INFO WARNING // ERROR must be solved, program shouldn't generate any error-level logs. ERROR // PANIC logs a message, then panics. PANIC // FATAL logs a message, then calls os.Exit(1). FATAL )
func (LogLevel) MarshalText ¶ added in v0.0.3
MarshalText instead of number
func (*LogLevel) UnmarshalText ¶ added in v0.0.3
UnmarshalText to number
type LogType ¶ added in v0.0.2
type LogType uint8
LogType log's type
func (LogType) MarshalText ¶ added in v0.0.3
MarshalText instead of number
func (*LogType) UnmarshalText ¶ added in v0.0.3
UnmarshalText to number
type Logger ¶
type Logger interface {
Debug(v ...interface{})
Debugf(format string, v ...interface{})
Info(v ...interface{})
Infof(format string, v ...interface{})
Warn(v ...interface{})
Warnf(format string, v ...interface{})
Error(v ...interface{})
Errorf(format string, v ...interface{})
Panic(v ...interface{})
Panicf(format string, v ...interface{})
Fatal(v ...interface{})
Fatalf(format string, v ...interface{})
}
Logger in tao
type MultiConfig ¶ added in v0.2.0
type MultiConfig[C any] interface { Config GetInstances() []Instance[C] SetInstances(instances []Instance[C]) GetDefaultInstanceName() string SetDefaultInstanceName(name string) }
MultiConfig 支持多实例的配置接口
type Parameter ¶
type Parameter interface {
Get(key string) (val interface{})
Set(key string, val interface{})
Clone() Parameter
Delete(key string)
String() string
}
Parameter describe function input or output
type PipeTask ¶ added in v0.1.0
type PipeTask struct {
Task
// contains filtered or unexported fields
}
PipeTask task in Pipeline
func NewPipeTask ¶
NewPipeTask constructor of PipeTask
type Pipeline ¶
Pipeline to run tasks in order pipeline is also a task
func NewPipeline ¶
func NewPipeline(name string, options ...PipelineOption) Pipeline
NewPipeline constructor of Pipeline
type PipelineOption ¶
type PipelineOption func(p *pipeline)
PipelineOption optional function of pipeline
func SetPostStartTask ¶
func SetPostStartTask(t *PipeTask) PipelineOption
SetPostStartTask of pipeline
type Task ¶
type Task interface {
Name() string
Run(ctx context.Context, param Parameter) error
Result() Parameter
Error() string
Close() error
State() TaskState
}
Task single Task