Skip to content

Commit

Permalink
Add an example to the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pearkes committed Jun 9, 2013
1 parent 5dbf3ec commit d73936d
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,53 @@ 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

```go
type stepAdd struct{}

func (s *stepAdd) Run(state map[string]interface{}) multistep.StepAction {
// Read our value and assert that it is they type we want
value := state["value"].(int)

fmt.Printf("Value is %d\n", value)

state["value"] = value + 1

return multistep.ActionContinue
}

func (s *stepAdd) Cleanup(map[string]interface{}) {}
```

Call your step from a runner.

```go
func main() {
// Our "bag of state" that we read the value from
state := make(map[string]interface{})

// Our intial value
state["value"] = 0

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

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

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

This will produce:

```
Value is 1
Value is 2
Value is 3
```

0 comments on commit d73936d

Please sign in to comment.