Skip to content

Using enum instead strings #95

Description

@suntong

The current approach of fsm is to use string to represent stages:

fsm/examples/simple.go

Lines 14 to 19 in e668a85

fsm := fsm.NewFSM(
"closed",
fsm.Events{
{Name: "open", Src: []string{"closed"}, Dst: "open"},
{Name: "close", Src: []string{"open"}, Dst: "closed"},
},

which is kind of error prone. These strings should better be replace with enum values instead, to

  • save space, and most importantly
  • allow compiler to do spellcheck for us

Like this:

type myFSM int

const (
	Init myFSM = iota
	Open
	Progress
	Close = Stop
)

For further details, check out https://pkg.go.dev/golang.org/x/tools/cmd/stringer

Please consider.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions