Documentation
¶
Index ¶
- type ActionFunc
- type Context
- type Listener
- type Pipeline
- func (p *Pipeline) AddBeforeHook(listener Listener) *Pipeline
- func (p *Pipeline) AddStep(step Step) *Pipeline
- func (p *Pipeline) AsNestedStep(name string) Step
- func (p *Pipeline) Run() Result
- func (p *Pipeline) WithBeforeHooks(listeners []Listener) *Pipeline
- func (p *Pipeline) WithContext(ctx Context) *Pipeline
- func (p *Pipeline) WithNestedSteps(name string, steps ...Step) Step
- func (p *Pipeline) WithSteps(steps ...Step) *Pipeline
- type Result
- type ResultHandler
- type Step
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionFunc ¶
ActionFunc is the func that contains your business logic. The context is a user-defined arbitrary data of type interface{} that gets provided in every Step, but nil if not set.
type Context ¶ added in v0.5.0
type Context interface{}
Context contains arbitrary data relevant for the pipeline execution.
type Listener ¶ added in v0.7.0
type Listener interface {
// Accept takes the given Step.
Accept(step Step)
}
Listener is a simple interface that listens to Pipeline events.
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline holds and runs intermediate actions, called "steps".
func NewPipeline ¶
func NewPipeline() *Pipeline
NewPipeline returns a new quiet Pipeline instance with KeyValueContext.
func NewPipelineWithContext ¶ added in v0.5.0
NewPipelineWithContext returns a new Pipeline instance with the given context.
func (*Pipeline) AddBeforeHook ¶ added in v0.7.0
AddBeforeHook adds the given listener to the list of hooks. See WithBeforeHooks.
func (*Pipeline) AddStep ¶
AddStep appends the given step to the Pipeline at the end and returns itself.
func (*Pipeline) AsNestedStep ¶
AsNestedStep converts the Pipeline instance into a Step that can be used in other pipelines. The properties are passed to the nested pipeline.
func (*Pipeline) Run ¶
Run executes the pipeline and returns the result. Steps are executed sequentially as they were added to the Pipeline. If a Step returns a Result with a non-nil error, the Pipeline is aborted its Result contains the affected step's error.
func (*Pipeline) WithBeforeHooks ¶ added in v0.7.0
WithBeforeHooks takes a list of listeners. Each Listener.Accept is called once in the given order just before the ActionFunc is invoked. The listeners should return as fast as possible, as they are not intended to do actual business logic.
func (*Pipeline) WithContext ¶ added in v0.5.0
WithContext returns itself while setting the context for the pipeline steps.
func (*Pipeline) WithNestedSteps ¶ added in v0.4.0
WithNestedSteps is similar to AsNestedStep, but it accepts the steps given directly as parameters.
type Result ¶
type Result struct {
// Err contains the step's returned error, nil otherwise.
Err error
// Name is an optional identifier for a result.
// ActionFunc may set this property before returning to help an ResultHandler with further processing.
Name string
}
Result is the object that is returned after each step and after running a pipeline.
func (Result) IsSuccessful ¶
IsSuccessful returns true if the contained error is nil.
type ResultHandler ¶ added in v0.3.0
ResultHandler is a func that gets called when a step's ActionFunc has finished with any Result.
type Step ¶
type Step struct {
// Name describes the step's human-readable name.
// It has no other uses other than easily identifying a step for debugging or logging.
Name string
// F is the ActionFunc assigned to a pipeline Step.
// This is required.
F ActionFunc
// H is the ResultHandler assigned to a pipeline Step.
// This is optional, and it will be called in any case if it is set after F completed.
// Use cases could be logging, updating a GUI or handle errors while continuing the pipeline.
// The function may return nil even if the Result contains an error, in which case the pipeline will continue.
// This function is called before the next step's F is invoked.
H ResultHandler
}
Step is an intermediary action and part of a Pipeline.
func NewStep ¶
func NewStep(name string, action ActionFunc) Step
NewStep returns a new Step with given name and action.
func NewStepFromFunc ¶ added in v0.5.0
NewStepFromFunc returns a new Step with given name using a function that expects an error.
func (Step) WithResultHandler ¶ added in v0.3.0
func (s Step) WithResultHandler(handler ResultHandler) Step
WithResultHandler sets the ResultHandler of this specific step and returns the step itself.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package parallel extends the command-pipeline core with concurrency steps.
|
Package parallel extends the command-pipeline core with concurrency steps. |
|
Package predicate provides functions that wrap existing actions but executes them only on conditions ("predicates").
|
Package predicate provides functions that wrap existing actions but executes them only on conditions ("predicates"). |