multistep

multistep is a Go library for building up complex actions using discrete steps.

  • Owner: mitchellh/multistep
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

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

Main metrics

Overview
Name With Ownermitchellh/multistep
Primary LanguageGo
Program languageGo (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2013-06-04 16:42:54
Pushed At2017-09-01 11:47:18
Last Commit At2017-03-16 11:53:39
Release Count0
用户参与
Stargazers Count149
Watchers Count8
Fork Count19
Commits Count34
Has Issues Enabled
Issues Count2
Issue Open Count1
Pull Requests Count4
Pull Requests Open Count3
Pull Requests Close Count1
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private