tao

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2021 License: Apache-2.0 Imports: 10 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"
)

* ErrorCode

View Source
const ConfigKey = "tao"

ConfigKey for this repo

Variables

View Source
var LevelPrefix = map[LogLevel]string{
	DEBUG:   "[D] ",
	INFO:    "[I] ",
	WARNING: "[W] ",
	ERROR:   "[E] ",
	PANIC:   "[P] ",
	FATAL:   "[F] ",
}

LevelPrefix to define log prefix of log level

View Source
var TaoLevel = DEBUG

TaoLevel to define the log level of tao

View Source
var TaoWriter io.Writer

TaoWriter for TaoLogger

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 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 by key of config

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 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 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 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 Error

type ErrorUnWrapper

type ErrorUnWrapper interface {
	error
	Unwrap() error
}

ErrorUnWrapper extension of error

func NewErrorUnWrapper

func NewErrorUnWrapper(format string, e error) ErrorUnWrapper

NewErrorUnWrapper constructor of errorUnWrap

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
)

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

var TaoLogger Logger

TaoLogger in global default to provide based log print

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 {
	LogLevel `json:"log_level"`
}

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 Task

type Task interface {
	Name() string
	Run(ctx context.Context, param Parameter) error
	Result() Parameter
	Error() string
	Close() error
}

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