Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Latest commit

 

History

History
60 lines (43 loc) · 1.35 KB

README.md

File metadata and controls

60 lines (43 loc) · 1.35 KB

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