Skip to content
multistep is a Go library for building up complex actions using discrete steps.
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE.md Need a license (mit) Jun 9, 2013
README.md
basic_runner.go fmt Aug 31, 2013
basic_runner_test.go Bring test coverate up to 100% Apr 6, 2014
debug_runner.go let wrapped steps expose their inner step name Mar 16, 2017
debug_runner_test.go
multistep.go
multistep_test.go Bring test coverate up to 100% Apr 6, 2014
statebag.go
statebag_test.go BasicStateBag and StateBag for safe concurrent map access Aug 31, 2013

README.md

multistep

multistep is a Go library for building up complex actions using discrete, individual "steps." These steps are strung together and run in sequence to achieve a more complex goal. The runner handles cleanup, cancelling, etc. if necessary.

Basic Example

Make a step to perform some action. The step can access your "state", which is passed between steps by the runner.

type stepAdd struct{}

func (s *stepAdd) Run(state multistep.StateBag) multistep.StepAction {
    // Read our value and assert that it is they type we want
    value := state.Get("value").(int)
    fmt.Printf("Value is %d\n", value)

	// Store some state back
	state.Put("value", value + 1)
    return multistep.ActionContinue
}

func (s *stepAdd) Cleanup(multistep.StateBag) {
	// This is called after all the steps have run or if the runner is
	// cancelled so that cleanup can be performed.
}

Make a runner and call your array of Steps.

func main() {
    // Our "bag of state" that we read the value from
    state := new(multistep.BasicStateBag)
	state.Put("value", 0)

    steps := []multistep.Step{
        &stepAdd{},
        &stepAdd{},
        &stepAdd{},
    }

    runner := &multistep.BasicRunner{Steps: steps}

    // Executes the steps
    runner.Run(state)
}

This will produce:

Value is 0
Value is 1
Value is 2
You can’t perform that action at this time.