wings/server/manager.go

47 lines
873 B
Go
Raw Normal View History

package server
import (
2021-01-22 22:38:11 +00:00
"github.com/pterodactyl/wings/remote"
)
type Manager interface {
// Initialize fetches all servers assigned to this node from the API.
Initialize(serversPerPage int) error
GetAll() []*Server
Get(uuid string) *Server
Add(s *Server)
Remove(s *Server)
}
type manager struct {
servers Collection
2021-01-22 22:38:11 +00:00
panelClient remote.Client
}
// NewManager creates a new server manager.
2021-01-22 22:38:11 +00:00
func NewManager(panelClient remote.Client) Manager {
return &manager{panelClient: panelClient}
}
func (m *manager) GetAll() []*Server {
return m.servers.items
}
func (m *manager) Get(uuid string) *Server {
return m.servers.Find(func(s *Server) bool {
return s.Id() == uuid
})
}
func (m *manager) Add(s *Server) {
s.manager = m
m.servers.Add(s)
}
func (m *manager) Remove(s *Server) {
m.servers.Remove(func(sf *Server) bool {
return sf.Id() == s.Id()
})
}