toml

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const FileName = "world.toml"

Variables

This section is empty.

Functions

func SetProject

func SetProject(content, project string) string

SetProject replaces the first project assignment in a world.toml document, which the World Engine templates define at the top level. It edits the text so comments and layout survive; a typed round-trip would drop every comment. If no project line exists the content is returned unchanged, and callers should validate afterwards (see WriteProject).

func WriteProject

func WriteProject(path, project string) error

WriteProject reads the world.toml at path, sets its project field to project, validates the result, and writes it back. It fails without writing if the file is missing or the edit yields an invalid world.toml (e.g. there was no project line to set).

Types

type Config

type Config struct {
	Organization string        `toml:"organization" json:"organization"`
	Project      string        `toml:"project"      json:"project"`
	Shards       []Shard       `toml:"shards"       json:"shards"`
	Services     []GameService `toml:"services"     json:"services"`
}

func Load

func Load(r io.Reader) (Config, error)

func LoadFile

func LoadFile(path string) (Config, error)

func (Config) ResolveInstanceIDs

func (c Config) ResolveInstanceIDs(ids []string) ([]Shard, error)

ResolveInstanceIDs returns the shard instances named by ids. Empty input selects every instance. Blank and duplicate IDs are ignored, request order is preserved, and any unknown ID fails the whole selection.

func (Config) ShardIDs

func (c Config) ShardIDs() []string

ShardIDs returns each world.toml shard ID once, in declaration order.

type GameService

type GameService struct {
	ID          string            `toml:"id"                    json:"id"`
	Image       string            `toml:"image,omitempty"       json:"image,omitempty"`
	Path        string            `toml:"path,omitempty"        json:"path,omitempty"`
	Env         map[string]string `toml:"env,omitempty"         json:"env,omitempty"`
	Ports       []int             `toml:"ports,omitempty"       json:"ports,omitempty"`       // host port == container port
	Volume      string            `toml:"volume,omitempty"      json:"volume,omitempty"`      // container mount path for a named volume
	Healthcheck []string          `toml:"healthcheck,omitempty" json:"healthcheck,omitempty"` // docker healthcheck Test array

	// ConfigDB marks the config database shards read game config from; the docker
	// backend derives DB_DSN from it and injects it into every shard's env.
	ConfigDB bool `toml:"config_db,omitempty" json:"config_db,omitempty"`

	// DB opts this source-built service into the project database (one DB per
	// project, shared by all shards and services). The docker backend
	// auto-provisions a single "{project}-db" Postgres (unless a config_db service
	// already provides one) and injects its DSN as DB_DSN. An explicit env wins.
	DB bool `toml:"db,omitempty" json:"db,omitempty"`
}

GameService is an auxiliary [[services]] container run alongside the shards by the docker backend (e.g. postgres, a headless service). Exactly one of Image (pulled) or Path (built from project Go source) is set. Ignored by k8s.

func (GameService) IsBuiltFromSource

func (g GameService) IsBuiltFromSource() bool

IsBuiltFromSource reports whether the service builds from project Go source (Path set) vs. running a pulled image (Image set). validate guarantees exactly one is set.

type Shard

type Shard struct {
	ID         string `toml:"id"                    json:"id"`
	LogLevel   string `toml:"log_level,omitempty"   json:"logLevel,omitempty"`
	EnableOTEL bool   `toml:"enable_otel,omitempty" json:"enableOtel,omitempty"`
	Path       string `toml:"path,omitempty"        json:"path,omitempty"`
	PoolSize   int    `toml:"pool_size,omitempty"   json:"poolSize,omitempty"`

	// TickRate is the game-loop frequency in Hz. Optional; k8s backend only.
	TickRate int32 `toml:"tick_rate,omitempty" json:"tickRate,omitempty"`

	// Mode is the shard mode (e.g. "LEADER"). Optional; k8s backend only.
	Mode string `toml:"mode,omitempty" json:"mode,omitempty"`

	// Resources is the per-instance CPU + memory request/limit pair.
	// Optional; k8s backend only. Nil means "use translator default."
	Resources *ShardResources `toml:"resources,omitempty" json:"resources,omitempty"`

	// InstanceID is the runtime shard instance ID after pool expansion. Pooled
	// replicas keep ID as the logical world.toml shard ID and get suffixed
	// InstanceIDs such as "game-2". Set during validation, not part of the schema.
	InstanceID string `toml:"-" json:"-"`
}

type ShardResourceValues

type ShardResourceValues struct {
	CPU    int32 `toml:"cpu"    json:"cpu"`
	Memory int32 `toml:"memory" json:"memory"`
}

ShardResourceValues uses milliCPU for CPU and MiB for Memory.

type ShardResources

type ShardResources struct {
	Requests ShardResourceValues `toml:"requests" json:"requests"`
	Limits   ShardResourceValues `toml:"limits"   json:"limits"`
}

ShardResources is the requests + limits pair, mirroring the ShardPool CRD.

Jump to

Keyboard shortcuts

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