Documentation ¶
Overview ¶
Package srvrepo defines the public (externally importable) interfaces, types, and functions for interacting with the server repository.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct { ServerAddress // embedded to flatten the structure Name string `json:"name"` GameVersion int `json:"game_version"` CurrentPlayers int `json:"current_players"` MaxPlayers int `json:"max_players"` IsJoinable bool `json:"is_joinable"` LastSeen jsonTime `json:"last_seen"` }
Server defines a structure for our server data.
type ServerAddress ¶
ServerAddress defines the structure of a server address.
func ParseServerAddress ¶
func ParseServerAddress(s string) (ServerAddress, error)
ParseServerAddress parses a string address into a ServerAddress, returning the parsed value and any errors that occurred during parsing.
func (*ServerAddress) String ¶
func (a *ServerAddress) String() string
String satisfies the fmt.Stringer interface and returns a string form of the ServerAddress structure.
func (*ServerAddress) Validate ¶
func (a *ServerAddress) Validate() error
Validate runs validations on the value and returns an error if the value is invalid for any reason.
type ServerRepository ¶
type ServerRepository struct {
// contains filtered or unexported fields
}
ServerRepository defines the structure for an in-memory server repository.
func NewServerRepository ¶
func NewServerRepository() *ServerRepository
NewServerRepository returns a pointer to a new initialized ServerRepository.
func (*ServerRepository) Has ¶
func (r *ServerRepository) Has(id ServerID) bool
Check if an given ServerID already exists in the repository
func (*ServerRepository) List ¶
func (r *ServerRepository) List() []Server
List returns a slice representation of the servers in the repository.
func (*ServerRepository) Prune ¶
func (r *ServerRepository) Prune(threshold time.Duration)
Prune takes a time.Duration representing the threshold of when a server's last-seen "age" should be considered too old, and removes those servers from the repository.
func (*ServerRepository) Register ¶
func (r *ServerRepository) Register(srv Server) (bool, error)
Register takes a Server and registers it with the repository, returning a bool that represents whether the server already existed or not (true for already exists, false otherwise), and a potential error if the registration failed.
func (*ServerRepository) Remove ¶
func (r *ServerRepository) Remove(id ServerID) bool
Remove takes a ServerID and removes the corresponding server from the repository, returning a bool that represents whether the server existed or not (true for exists, false otherwise).