Finite-state machine in go
Go
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
README.md
errors.go
fsm.go
fsm_test.go
repo.go
transaction.go

README.md

fsm

Finite-state machine in go

  • Build Status
  • GoDoc

Introduction

Feature

  • Supports add transactions from configure file

Installation

go get -u github.com/go-trellis/fsm

Usage

fsm repo

// FSMRepo the functions of fsm interface
type FSMRepo interface {
    // add a transction into cache
    Add(*Transaction)
    // remove all transactions
    Remove()
    // remove namespace's transactions
    RemoveNamespace(namespace string)
    // remove a transaction by information
    RemoveByTransaction(*Transaction)
    // get target transaction by current information
    GetTargetTranstion(namespace, curStatus, event string) *Transaction
}

new and input a namespace's transaction

    f := fsm.New()

    f.Add(&fsm.Transaction{
            Namespace:     "namespace",
            CurrentStatus: "status1",
            Event:         "event1",
            TargetStatus:  "status2",
        })
    fmt.Println(f.GetTargetTranstion("namespace", "status1", "event1"))

    f.Remove()

    fmt.Println(f.GetTargetTranstion("namespace", "status1", "event1"))