Categorygithub.com/mitchellh/multistep
modulepackage
0.0.0-20170316185339-391576a156a5
Repository: https://github.com/mitchellh/multistep.git
Documentation: pkg.go.dev

# README

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

# Functions

DebugPauseDefault is the default pause function when using the DebugRunner if no PauseFn is specified.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
This is the key set in the state bag when using the basic runner to signal that the step sequence was cancelled.
This is the key set in the state bag when a step halted the sequence.

# Structs

BasicRunner is a Runner that just runs the given slice of steps.
BasicStateBag implements StateBag by using a normal map underneath protected by a RWMutex.
DebugRunner is a Runner that runs the given set of steps in order, but pauses between each step until it is told to continue.

# Interfaces

Runner is a thing that runs one or more steps.
StateBag holds the state that is used by the Runner and Steps.
Step is a single step that is part of a potentially large sequence of other steps, responsible for performing some specific action.
StepWrapper is an interface that wrapped steps can implement to expose their inner step names to the debug runner.

# Type aliases

DebugLocation is the location where the pause is occuring when debugging a step sequence.
DebugPauseFn is the type signature for the function that is called whenever the DebugRunner pauses.
A StepAction determines the next step to take regarding multi-step actions.