go-fsm-generator

command module
v0.0.0-...-88c9cb4 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

README

Go Report Card

Finite state machine generation tool

go-fsm-generator generates all states, events and behavioral interfaces for your state machine.

  • It will statically analyze you FSM definition and can point out some problems during generation.
  • Generated code designed to prevent impossible state transitions, so it is easy and safe to use.
  • Automatically detects terminal states.
  • Visualize your FSM in generation time and in runtime using Graphwiz notation [dot].
  • Created with go generate in mind.

Example

As an demonstration we have implemented circuit breaker state machine in examples folder.

We use simple struct fields to declare FSM states and field tags to define state transitions.

//go:generate ../go-fsm-generator -type CBMDeclaration -v

type FSMState int

type CBMDeclaration struct {
	Opened     FSMState `Try:"HalfOpened"`
	HalfOpened FSMState `Success:"Closed",Failure:"Opened",Panic:"Exit"`
	Closed     FSMState `Error:"Opened",Panic:"Exit"`
	Exit       FSMState
}

As an result we will get flowing FSM

Circuit Breaker FSM visualization

Take a look at examples folder for details.

License

Copyright 2018 Bohdan Storozhuk

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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