Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using enum instead strings #95

Open
suntong opened this issue Feb 25, 2023 · 0 comments
Open

Using enum instead strings #95

suntong opened this issue Feb 25, 2023 · 0 comments

Comments

@suntong
Copy link

suntong commented Feb 25, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant