fsm

package
v0.0.0-...-987fb27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2021 License: GPL-3.0 Imports: 3 Imported by: 0

README

fsm

Finite-state machine in go

Introduction

Installation

go get -u trellis.tech/trellis/common.v0/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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTransaction = errcode.New("invalid transaction")
	ErrTargetStatusEmpty  = errcode.New("empty target status")
)

errors

Functions

func NewTransactionFromConfig

func NewTransactionFromConfig(filepath string) error

NewTransactionFromConfig new transactions from config file

func NewTransactions

func NewTransactions(cfg config.Config) (err error)

NewTransactions new transactions

Types

type Repo

type Repo interface {
	// Add a transaction into cache
	Add(*Transaction)
	// Remove all transactions
	Remove()
	// RemoveNamespace remove namespace's transactions
	RemoveNamespace(namespace string)
	// RemoveByTransaction remove a transaction by information
	RemoveByTransaction(*Transaction)
	// GetTargetTransaction get target transaction by current information
	GetTargetTransaction(namespace, curStatus, event string) *Transaction
}

Repo the functions of fsm interface

func New

func New() Repo

New get default fsm

type Transaction

type Transaction struct {
	Namespace     string `json:"namespace"`
	CurrentStatus string `json:"current"`
	Event         string `json:"event"`
	TargetStatus  string `json:"target"`
}

Transaction information for current to target status in namespace

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL