The state
package provides a simple and flexible way to manage the state within a Go application. It allows you to initialize, switch, and retrieve states using a map-based approach.
To install the package, use the following command:
go get github.com/navid-ka/gostate@latest
import "github.com/navid-ka/gostate"
To create a new state instance, use the NewState function:
s := state.NewState()
The InitState method allows you to initialize the state with a map of keys (state names) and their corresponding boolean values.
initialStates := map[string]bool{
"INIT": true,
"GAME": false,
"EXIT": false,
}
s.InitState(initialStates)
s.SwitchState("GAME")
isGameActive := s.Get("GAME")
if isGameActive {
// Perform actions related to the GAME state
}