srvrepo

package
v0.0.0-...-283e58d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2020 License: MIT Imports: 8 Imported by: 0

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.

func (*Server) ID

func (s *Server) ID() ServerID

ID returns the ServerID for a server, generated based on its internal data.

func (*Server) Seen

func (s *Server) Seen()

Seen marks the server as "seen", updating the `LastSeen` property value.

func (*Server) Validate

func (s *Server) Validate() error

Validate runs validations on the value and returns an error if the value is invalid for any reason.

type ServerAddress

type ServerAddress struct {
	IP   net.IP `json:"ip"`
	Port int    `json:"port"`
}

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 ServerID

type ServerID string

ServerID defines the identifier of a particular server.

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL