tao

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: Apache-2.0 Imports: 13 Imported by: 14

README

tao

___________              
\__    ___/____    ____  
  |    |  \__  \  /  _ \ 
  |    |   / __ \(  <_> )
  |____|  (____  /\____/ 
               \/

The Tao produced One; One produced Two; Two produced Three; Three produced All things.

Documentation

Index

Constants

View Source
const (
	Unknown         = "Unknown"
	ParamInvalid    = "ParamInvalid"
	ContextCanceled = "ContextCanceled"
	DuplicateCall   = "DuplicateCall"
	TaskRunTwice    = "TaskRunTwice"
	TaskCloseTwice  = "TaskCloseTwice"
	TaskClosed      = "TaskClosed"
	TaskRunning     = "TaskRunning"
	ConfigNotFound  = "ConfigNotFound"
	UniverseNotInit = "UniverseNotInit"
)

* ErrorCode

View Source
const ConfigKey = "tao"

ConfigKey for this repo

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

Debug function wrap of TaoLogger

func Debugf

func Debugf(format string, v ...interface{})

Debugf function wrap of TaoLogger

func DeleteLogger added in v0.0.3

func DeleteLogger(configKey string) error

DeleteLogger of tao

func DeleteWriter added in v0.0.3

func DeleteWriter(configKey string) error

DeleteWriter of tao

func DevelopMode added in v0.0.4

func DevelopMode()

DevelopMode called to enable default configs for all

func Error

func Error(v ...interface{})

Error function wrap of TaoLogger

func Errorf

func Errorf(format string, v ...interface{})

Errorf function wrap of TaoLogger

func Fatal

func Fatal(v ...interface{})

Fatal function wrap of TaoLogger

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf function wrap of TaoLogger

func GetConfigBytes

func GetConfigBytes(key string) ([]byte, error)

GetConfigBytes in json schema by key of config

func GetWriter added in v0.0.3

func GetWriter(configKey string) io.Writer

GetWriter in tao

func Info

func Info(v ...interface{})

Info function wrap of TaoLogger

func Infof

func Infof(format string, v ...interface{})

Infof function wrap of TaoLogger

func NewPipeTask

func NewPipeTask(task Task, runAfter ...string) *pipeTask

NewPipeTask constructor of pipeTask

func Panic

func Panic(v ...interface{})

Panic function wrap of TaoLogger

func Panicf

func Panicf(format string, v ...interface{})

Panicf function wrap of TaoLogger

func Register added in v0.0.4

func Register(configKey string, fn func() error) error

Register to tao universe

func Run

func Run(ctx context.Context, param Parameter) (err error)

Run tao

func SetConfig

func SetConfig(key string, c Config) error

SetConfig by key & Config

func SetConfigBytesAll added in v0.0.2

func SetConfigBytesAll(data []byte, configType ConfigType) (err error)

SetConfigBytesAll from config file or code

func SetConfigPath added in v0.0.4

func SetConfigPath(confPath string)

SetConfigPath in init of your project

func SetLogger added in v0.0.3

func SetLogger(configKey string, logger Logger) error

SetLogger to tao

func SetWriter added in v0.0.3

func SetWriter(configKey string, w io.Writer) error

SetWriter to tao

func Warn

func Warn(v ...interface{})

Warn function wrap of TaoLogger

func Warnf

func Warnf(format string, v ...interface{})

Warnf function wrap of TaoLogger

Types

type Config

type Config interface {
	// Default config
	Default() Config
	// 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 ConfigType = iota
	Yaml
	Json
)

type ErrorTao

type ErrorTao interface {
	error
	Code() string
	Wrap(err error)
	Cause() error
}

ErrorTao extension of error, wrap of error

func NewError

func NewError(code, message string, a ...interface{}) ErrorTao

NewError constructor of ErrorTao

type ErrorUnWrapper

type ErrorUnWrapper interface {
	error
	Unwrap() error
}

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 Log added in v0.0.2

type Log struct {
	Level LogLevel `json:"level"`
	Type  LogType  `json:"type"`
	Path  string   `json:"path,omitempty"`
}

Log config in tao

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

func (l LogLevel) MarshalText() ([]byte, error)

MarshalText instead of number

func (LogLevel) String added in v0.0.3

func (l LogLevel) String() string

String for LogLevel Config

func (*LogLevel) UnmarshalText added in v0.0.3

func (l *LogLevel) UnmarshalText(text []byte) error

UnmarshalText to number

type LogType added in v0.0.2

type LogType uint8

LogType log's type

const (
	Console LogType = 1 // 0b1
	File    LogType = 2 // 0b10
)

func (LogType) MarshalText added in v0.0.3

func (l LogType) MarshalText() ([]byte, error)

MarshalText instead of number

func (LogType) String added in v0.0.3

func (l LogType) String() string

String for LogType Config

func (*LogType) UnmarshalText added in v0.0.3

func (l *LogType) UnmarshalText(text []byte) error

UnmarshalText to number

type Logger

type Logger interface {
	Debug(calldepth int, v ...interface{})
	Debugf(calldepth int, format string, v ...interface{})
	Info(calldepth int, v ...interface{})
	Infof(calldepth int, format string, v ...interface{})
	Warn(calldepth int, v ...interface{})
	Warnf(calldepth int, format string, v ...interface{})
	Error(calldepth int, v ...interface{})
	Errorf(calldepth int, format string, v ...interface{})
	Panic(calldepth int, v ...interface{})
	Panicf(calldepth int, format string, v ...interface{})
	Fatal(calldepth int, v ...interface{})
	Fatalf(calldepth int, format string, v ...interface{})
}

Logger in tao

func GetLogger added in v0.0.3

func GetLogger(configKey string) Logger

GetLogger in tao

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

func NewParameter

func NewParameter() Parameter

NewParameter constructor of Parameter

type Pipeline

type Pipeline interface {
	Task
	Register(task *pipeTask) error
}

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

func SetPreStopTask

func SetPreStopTask(t *pipeTask) PipelineOption

SetPreStopTask of pipeline

type TaoConfig

type TaoConfig struct {
	*Log       `json:"log"`
	HideBanner bool `json:"hide_banner"`
}

TaoConfig implements Config

func (*TaoConfig) Default

func (t *TaoConfig) Default() Config

Default config

func (*TaoConfig) RunAfter

func (t *TaoConfig) RunAfter() []string

RunAfter defines pre task names

func (*TaoConfig) ToTask

func (t *TaoConfig) ToTask() Task

ToTask transform itself to Task

func (*TaoConfig) ValidSelf

func (t *TaoConfig) ValidSelf()

ValidSelf with some default values

type TaoLogger

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

TaoLogger for tao

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

func NewTask

func NewTask(name string, fun TaskRun, options ...TaskOption) Task

NewTask constructor of Task

type TaskOption

type TaskOption func(t *task)

TaskOption optional function of task

func SetClose

func SetClose(cf func() error) TaskOption

SetClose of task

func SetPostStart

func SetPostStart(tr TaskRun) TaskOption

SetPostStart of task

func SetPreStop

func SetPreStop(tr TaskRun) TaskOption

SetPreStop of task

type TaskRun

type TaskRun func(ctx context.Context, param Parameter) (Parameter, error)

TaskRun with param

type TaskState

type TaskState uint8

TaskState to describe state of task

const (
	Runnable TaskState = iota
	Running
	Over
	Close
)

Jump to

Keyboard shortcuts

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