chore: refactor structure
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/iliadenisov/galaxy/internal/controller"
|
||||
"github.com/iliadenisov/galaxy/internal/model/game"
|
||||
)
|
||||
|
||||
func LoadState(configure func(*controller.Param)) (g game.Game, err error) {
|
||||
control(configure, func(c *controller.Ctrl) { c.ExecuteInit(func(r controller.Repo) { g, err = c.Repo.LoadState() }) })
|
||||
return
|
||||
}
|
||||
|
||||
func GenerateGame(configure func(*controller.Param), races []string) (gameID uuid.UUID, err error) {
|
||||
control(configure, func(c *controller.Ctrl) {
|
||||
c.ExecuteInit(func(r controller.Repo) { gameID, err = controller.NewGame(r, races) })
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func control(configure func(*controller.Param), consumer func(*controller.Ctrl)) error {
|
||||
c, err := controller.NewController(configure)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
consumer(c)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user