La referencia de API proviene de los comentarios de documentación de Go en el código fuente y está redactada en inglés.
package console
import "github.com/nsgo-dev/game/pkg/online/admin/console"Resumen
Package console is experimental: its API and documented formats may change in a minor release. See the API stability policy.
It is the operator console of the self-hosted services, a web app written with NSGo (its source is in internal/web) whose build the package embeds, and serves from an admin listener at /admin/ (Handler, Serve), the origin of the listener's session cookie, so it needs no CORS for the service that serves it. The service daemons pass Serve as admin.ListenOptions.Console; a player-facing listener never serves it, and without an admin listener nothing does.
The console signs an operator in to each service's admin listener (password and TOTP), shows each page only to an operator whose role has its permission and leaves out the actions the role lacks, and asks for a confirmation and a reason before a destructive action, sending the reason in admin.ReasonHeader so it lands in the audit record. Its pages are a dashboard (each service's readiness and metrics, and the game server's runtime), players (search, an account's identities, sessions, suspension, saves and scores, with suspend, unlink, revoke, export and delete), cloud save (slots, versions, download and restore), leaderboards (boards and entries, delete, hide and reset), the live server (matches, rooms and peers), the audit log with filters, and the operators, read-only, since operators.yaml stays the source of truth.
When the services' admin listeners are on several origins, console.yaml (Config) gives the origin of each, named by the console field of the admin: block of the listener that serves the console; each other listener lists the console's origin in its allowedOrigins.
The embedded build is regenerated with go generate ./pkg/online/admin/console, which runs internal/consolebuild, which also records the build's inputs in dist.inputs; CI fails when the sources' inputs differ from them. Files lists what it embeds, and the console's test holds its WebAssembly module to benchmarks/admin-console-budget.json.
Índice
Constantes
const (
ServiceAccounts = "accounts"
ServiceCloudsave = "cloudsave"
ServiceLeaderboard = "leaderboard"
ServiceServer = "server"
)Names of the services a console manages, as Services and the console's pages name them.
const ConfigPath = Prefix + "console.json"ConfigPath is where the console reads its configuration: the title, the service whose listener serves it and the origins of the others' admin APIs, as JSON.
const Prefix = "/admin/"Prefix is the path the console is served under on an admin listener.
const Version = 1Version is the console.yaml schema version this package reads and writes.
Funciones
func Files() (map[string]int64, error)Files returns the names and sizes in bytes of the files the console's build embeds, as they are stored: the WebAssembly module gzipped, the rest as written. The console's size budget reads it.
func Handler(o Options) (http.Handler, error)Handler returns the handler of the operator console: GET and HEAD of Prefix and the build's files under it, and ConfigPath; an admin listener serves it for every path under Prefix outside /admin/v1/. It answers "/admin" with a redirect to Prefix, any other method with 405 and a file the build does not have with 404. The WebAssembly module is sent gzipped, decompressed for a client that does not accept gzip. Files whose names carry a content hash may be cached for a year; the page, nsgo.json and ConfigPath are revalidated on every load. Every response forbids framing and sniffing, and its Content-Security-Policy lets the page run scripts only from its own origin and connect only to it and the origins Options.Config lists.
func Open(name string) (fs.File, error)Open opens one of the files the console's build embeds, by a name Files returns.
func Serve(configPath, service string) (http.Handler, error)Serve returns the console's handler for the admin listener of service, with the console.yaml at configPath when it is not empty. It is the admin.ListenOptions.Console of the service daemons.
func ServiceNames() []stringServiceNames returns the names of the services a console manages, in the order its pages list them.
Tipos
type Config struct {
// Version is the schema version; it must be Version.
Version int `yaml:"version"`
// Title is the console's title, such as the game's name: 1 to MaxTitleRunes printable characters, or empty for "Operator console".
Title string `yaml:"title,omitempty"`
// Services are the origins of the services' admin listeners.
Services Services `yaml:"services,omitempty"`
}Config is console.yaml, which the admin: block's console field names: what the console shows as its title and where it finds the admin API of each service it manages.
version: 1 title: Star Catcher services: accounts: https://admin-accounts.example.com cloudsave: https://admin-cloudsave.example.com leaderboard: https://admin-leaderboard.example.com server: https://admin-server.example.com
Each service entry is the origin of that service's admin listener, which serves its admin API under /admin/v1/; the console calls it from the browser with the operator's session on that listener, so the listener lists the console's origin in its allowedOrigins. The service whose listener serves the console needs no entry: the console reaches it on its own origin. A service without an entry, other than that one, has no page. Unknown fields, duplicate keys and trailing documents are refused, and Marshal writes the fields in the order above with 2-space indentation, so a file in that form reads back and writes again byte for byte.
func Load(path string) (*Config, error)Load reads and parses the console.yaml at path; its errors name the file, line and field.
func Parse(data []byte) (*Config, error)Parse decodes and validates console.yaml. Unknown fields, duplicate keys, a missing or unsupported version and trailing documents are refused, with errors that name the line and field.
func (c *Config) Marshal() ([]byte, error)Marshal validates c and encodes it as deterministic 2-space YAML.
func (c *Config) Validate() errorValidate checks that c is a version 1 console configuration with a printable title and an origin for each service it names.
type Options struct {
// Config is console.yaml; nil serves the console with no title and only the service of the listener serving it.
Config *Config
// Service names the service whose admin listener serves the console, such as "accounts"; the console reaches it on its own origin. Empty for a listener of no service in ServiceNames.
Service string
}Options configure a console Handler.
type Services struct {
// Accounts is the account service's admin listener (accountsd).
Accounts string `yaml:"accounts,omitempty"`
// Cloudsave is the cloud save service's admin listener (cloudsaved).
Cloudsave string `yaml:"cloudsave,omitempty"`
// Leaderboard is the leaderboard service's admin listener (leaderboardd).
Leaderboard string `yaml:"leaderboard,omitempty"`
// Server is a game server's admin listener, which mounts gameserver.Inspector.
Server string `yaml:"server,omitempty"`
}Services are the origins of the services' admin listeners, each an http or https origin such as https://admin.example.com with no path, or empty.
func (s Services) Origin(name string) stringOrigin returns the origin configured for the service name, empty when it has none or name is not a service.
func (s Services) Origins() []stringOrigins returns the origins the services list, in ServiceNames order, each once.