Specify the persistence path using the command line

This commit is contained in:
Marc Di Luzio 2020-06-02 16:10:45 +01:00
parent c085e56954
commit 5033ec4e63
5 changed files with 36 additions and 18 deletions

View file

@ -31,7 +31,8 @@ type Server struct {
server *http.Server
router *mux.Router
persistence int
persistence int
persistenceLocation string
sync sync.WaitGroup
}
@ -47,9 +48,10 @@ func OptionPort(port int) ServerOption {
}
// OptionPersistentData sets the server data to be persistent
func OptionPersistentData() ServerOption {
func OptionPersistentData(loc string) ServerOption {
return func(s *Server) {
s.persistence = PersistentData
s.persistenceLocation = loc
}
}
@ -61,7 +63,6 @@ func NewServer(opts ...ServerOption) *Server {
// Set up the default server
s := &Server{
port: 8080,
accountant: accounts.NewAccountant(),
world: game.NewWorld(),
persistence: EphemeralData,
router: router,
@ -75,6 +76,9 @@ func NewServer(opts ...ServerOption) *Server {
// Set up the server object
s.server = &http.Server{Addr: fmt.Sprintf(":%d", s.port), Handler: router}
// Create the accountant
s.accountant = accounts.NewAccountant(s.persistenceLocation)
return s
}