fsm

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2019 License: Apache-2.0 Imports: 7 Imported by: 2

README

fsm

Documentation Go Report Card Maintainability Coverage Status CircleCI

finite state machine with dot graph bonus

Running the example

go run cmd/main.go

Input json graph ./example/graph.json

example graph

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action represents an action

type Graph

type Graph map[Status]*Node

Graph represent the container of all nodes

func NewGraph

func NewGraph() Graph

NewGraph will create a new Graph

func (Graph) AddNode

func (g Graph) AddNode(n *Node) error

AddNode will add a node to the state graph

func (Graph) GeneratePNG

func (g Graph) GeneratePNG(f io.Writer) error

GeneratePNG will generate a png from the graph dependency on dot

func (Graph) GetOutcomeStatus

func (g Graph) GetOutcomeStatus(st Status, ac Action) (Status, error)

GetOutcomeStatus will return the potential outcomes for a curr status

func (Graph) MarshalJSON

func (g Graph) MarshalJSON() ([]byte, error)

MarshalJSON will return json

func (Graph) UnmarshalJSON

func (g Graph) UnmarshalJSON(data []byte) error

UnmarshalJSON will parse a json into a tree of nodes

func (Graph) Viz

func (g Graph) Viz() *dot.Graph

Viz will create the graphviz graph for the graph

type Node

type Node struct {
	Sources  []StatusAction `json:"sources,omitempty"`
	Status   Status         `json:"status"`
	Outcomes []StatusAction `json:"outcomes,omitempty"`
}

Node represent a Node in the state graph

func (*Node) String added in v1.0.1

func (n *Node) String() string

type Status

type Status string

Status represent a status

type StatusAction

type StatusAction struct {
	Action Action `json:"action"`
	Status Status `json:"status"`
}

StatusAction represents either an action and its origin state (Source) an action and its state resulting of the action applied (Outcome)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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