iTrellis / fsm

Finite-state machine in go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fsm

Achieve this repo, move it into github.com/iTellis/common

Finite-state machine in go

  • GoDoc

Introduction

Installation

go get -u github.com/iTrellis/common/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"))

Config

About

Finite-state machine in go

License:GNU General Public License v3.0


Languages

Language:Go 100.0%