types

package
v0.0.0-...-c84f994 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2021 License: GPL-3.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressFromString

func AddressFromString(input string) (output string, errs []error)

AddressFromString validates an address field for a server and ensures it contains the correct combination of host:port with either "samp://" or an empty scheme. returns an address with the :7777 port if absent (this is the default SA:MP port) and strips the "samp:// protocol".

Types

type Config

type Config struct {
	Version         string
	Bind            string        `split_words:"true" required:"true"`
	MongoHost       string        `split_words:"true" required:"true"`
	MongoPort       string        `split_words:"true" required:"true"`
	MongoName       string        `split_words:"true" required:"true"`
	MongoUser       string        `split_words:"true" required:"true"`
	MongoPass       string        `split_words:"true" required:"false"`
	MongoCollection string        `split_words:"true" required:"true"`
	QueryInterval   time.Duration `split_words:"true" required:"true"`
	MaxFailedQuery  int           `split_words:"true" required:"true"`
	VerifyByHost    bool          `split_words:"true" required:"true"`
	LegacyList      bool          `split_words:"true" required:"true"`
}

Config stores app global configuration

type FilterAttribute

type FilterAttribute string

FilterAttribute represents a filter to apply to results

const FilterEmpty FilterAttribute = "empty"

FilterEmpty filters out empty servers

const FilterFull FilterAttribute = "full"

FilterFull filters out full servers

const FilterPassword FilterAttribute = "password"

FilterPassword filters out servers with passwords

type PageSize

type PageSize int

PageSize represents a query page size parameter

const PageSizeDefault PageSize = 5000

PageSizeDefault controls the default page size of listings

type Route

type Route struct {
	Name        string           `json:"name"`
	Method      string           `json:"method"`
	Path        string           `json:"path"`
	Description string           `json:"description"`
	Params      url.Values       `json:"params"`
	Accepts     interface{}      `json:"accepts"`
	Returns     interface{}      `json:"returns"`
	Handler     http.HandlerFunc `json:"-"`
}

Route represents an API route and its associated handler function

type RouteHandler

type RouteHandler interface {
	Version() string
	Routes() []Route
}

RouteHandler represents an version group of API endpoints

type Server

type Server struct {
	IP          string            `json:"ip"`
	Core        ServerCore        `json:"core"`
	Rules       map[string]string `json:"ru,omitempty"`
	Description string            `json:"description"`
	Banner      string            `json:"banner"`
	Active      bool              `json:"active"`
}

Server contains all the information associated with a game server including the core information, the standard SA:MP "rules" and "players" lists as well as any additional fields to enhance the server browsing experience.

func (Server) Example

func (server Server) Example() Server

Example returns an example of Server

func (*Server) Validate

func (server *Server) Validate() (errs []error)

Validate checks the contents of a Server object to ensure all the required fields are valid.

type ServerCore

type ServerCore struct {
	Address    string `json:"ip"`
	Hostname   string `json:"hn"`
	Players    int    `json:"pc"`
	MaxPlayers int    `json:"pm"`
	Gamemode   string `json:"gm"`
	Language   string `json:"la"`
	Password   bool   `json:"pa"`
	Version    string `json:"vn"`
}

ServerCore stores the standard SA:MP 'info' query fields necessary for server lists. The json keys are short to cut down on network traffic since these are the objects returned to a listing request which could contain hundreds of objects.

type ServerListParams

type ServerListParams struct {
	Page     int
	PageSize PageSize
	Sort     SortOrder
	By       SortColumn
	Filters  []FilterAttribute
}

ServerListParams represents the URL query parameters for server listing

func (ServerListParams) Example

func (slp ServerListParams) Example() (result url.Values)

Example returns an example of ServerListParams in url.Values format

type SortColumn

type SortColumn string

SortColumn represents a column to sort results by

const ByPlayers SortColumn = "player"

ByPlayers means the list will use the amount of players as a sort key

type SortOrder

type SortOrder string

SortOrder represents a query result sort order

const SortAsc SortOrder = "asc"

SortAsc is the ascending sort order for listings

const SortDesc SortOrder = "desc"

SortDesc is the descending sort order for listings

type Statistics

type Statistics struct {
	Servers          int     `json:"servers"`
	Players          int     `json:"players"`
	PlayersPerServer float32 `json:"players_per_server"`
}

Statistics represents a set of simple metrics for the entire listing database

func (Statistics) Example

func (s Statistics) Example() Statistics

Example returns an example of Statistics

Jump to

Keyboard shortcuts

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