tao

package module
v0.1.6 Latest Latest
Warning

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

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

README

tao

MainTest Go Report Card codecov GoDoc GitHub release (latest by date)

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

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

View Source
var Add = tao.Add

Add of tao

View Source
var Done = tao.Done

Done of tao

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() error

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 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 LoadConfig added in v0.1.5

func LoadConfig(configKey string, config Config) error

LoadConfig by key of config

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, config Config, setup func() error) error

Register unit to tao universe

func Run

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

Run tao

func SetAllConfigBytes added in v0.1.4

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

SetAllConfigBytes from config file or code

func SetConfig

func SetConfig(configKey string, config Config) error

SetConfig by key & Config

func SetConfigPath added in v0.0.4

func SetConfigPath(confPath string) error

SetConfigPath in your project's init()

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 Banner struct {
	Hide    bool   `json:"hide"`
	Content string `json:"content"`
}

Banner config

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 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"`
	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

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

MarshalText instead of number

func (LogFlag) String added in v0.1.4

func (l LogFlag) String() string

String for LogType Config

func (*LogFlag) UnmarshalText added in v0.1.4

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

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

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 log
	Console LogType = 1 // 0b1
	// File log
	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(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

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 PipeTask added in v0.1.0

type PipeTask struct {
	Task
	// contains filtered or unexported fields
}

PipeTask task in Pipeline

func NewPipeTask

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

NewPipeTask constructor of PipeTask

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 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 task
	Runnable TaskState = iota
	// Running task
	Running
	// Over task
	Over
	// Closed task
	Closed
)

type Universe added in v0.1.2

type Universe struct {
	sync.WaitGroup

	Pipeline
	// contains filtered or unexported fields
}

Universe of tao

Jump to

Keyboard shortcuts

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