pack

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pack is the server side of the spec: it builds a file manifest from a folder and writes a starter server profile. The d2pack command wraps it for server teams.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildManifest

func BuildManifest(dir string, opts Options) (*spec.Manifest, error)

BuildManifest hashes every file under dir into a manifest.

func GenerateKey

func GenerateKey() (private []byte, public string, err error)

GenerateKey makes a manifest signing key. It returns the private key as a PEM file to keep secret, and the public key as the profile's signing.keys gives it.

func InitProfile

func InitProfile(opts InitOptions) ([]byte, error)

InitProfile writes a starter server profile: the minimum a server needs to be listed, ready to extend with branding, components and settings.

func LoadKey

func LoadKey(file string) (ed25519.PrivateKey, error)

LoadKey reads a signing key written by GenerateKey.

func SignManifestFile

func SignManifestFile(file string, key ed25519.PrivateKey) error

SignManifestFile writes a manifest's signature beside it, as <manifest>.sig.

func WriteManifest

func WriteManifest(m *spec.Manifest, file string) error

WriteManifest writes a manifest as indented JSON.

Types

type BuildOptions

type BuildOptions struct {
	// Version is written into every manifest.
	Version string
	// Out is the folder to build into. It must not exist yet.
	Out string
	// Key signs every manifest, and must be one of the profile's
	// signing.keys. It is needed exactly when the profile has keys.
	Key ed25519.PrivateKey
	// Previous, when set, is a folder holding the manifests published now,
	// laid out as Out is (<host>/<path>). A file a previous manifest listed
	// that the new one doesn't becomes a delete entry, as do its delete
	// entries, so players who skip a release still lose files dropped
	// since.
	Previous string
}

BuildOptions control Build.

type BuildResult

type BuildResult struct {
	Built []Built
	// NotBuilt lists channels and component versions in the profile that the
	// plan has no entry for. Their published manifests are left as they are.
	NotBuilt []string
}

BuildResult is what Build did.

func Build

func Build(plan *Plan, opts BuildOptions) (*BuildResult, error)

Build builds every manifest in the plan into opts.Out, laid out as <host>/<path> mirroring their URLs, with each manifest's files next to it, ready to upload. Every manifest is checked against the profile. Out is written in full or not at all.

type Built

type Built struct {
	Name     string
	Manifest string
	Files    int
	Bytes    int64
}

Built is one manifest Build wrote.

type InitOptions

type InitOptions struct {
	ID          string
	Name        string
	Gateway     string
	GameVersion string
	// ManifestURL is where the live channel's manifest.json is published.
	ManifestURL string
	// ReportURL, if set, is where the launcher sends bug reports. Its host
	// joins the profile's hosts.
	ReportURL string
}

InitOptions describe a new server, for InitProfile.

type Options

type Options struct {
	Server  string
	Version string
	// BaseURL is where the folder is published. Each file's URL is BaseURL
	// plus its path.
	BaseURL string
	// Once lists patterns for files the player owns after the first install,
	// such as maphack settings. Matched case-insensitively against the path.
	Once []string
	// Exclude lists patterns for files to leave out.
	Exclude []string
	// Only, when set, keeps just the files matching one of these patterns,
	// for building a component's manifest from a full install.
	Only []string
}

Options control how a folder becomes a manifest.

type Plan

type Plan struct {
	// Profile is the server profile the manifests are for. The manifest URLs
	// come from it, so the plan never repeats them.
	Profile string `json:"profile"`
	// Source is the folder of game files, used by every entry that doesn't
	// name its own.
	Source Sources `json:"source,omitempty"`
	// Exclude applies to every entry, for junk such as logs and readmes.
	Exclude   []string    `json:"exclude,omitempty"`
	Manifests []PlanEntry `json:"manifests"`
}

Plan says how to build every manifest a server publishes in one go: the channels and each component version, from folders of game files. It lives in a JSON file next to the server's profile; see LoadPlan.

func LoadPlan

func LoadPlan(file string) (*Plan, error)

LoadPlan reads a plan. Relative paths in it are relative to the plan file.

type PlanEntry

type PlanEntry struct {
	Channel   string `json:"channel,omitempty"`
	Component string `json:"component,omitempty"`
	Version   string `json:"version,omitempty"`
	// Source overrides the plan's Source, for a component kept in its own
	// folder.
	Source Sources `json:"source,omitempty"`
	// Files is the URL the files are published at, when that isn't the folder
	// the manifest is published in. A source with its own Files overrides it
	// for that source's files.
	Files   string   `json:"files,omitempty"`
	Once    []string `json:"once,omitempty"`
	Exclude []string `json:"exclude,omitempty"`
	Only    []string `json:"only,omitempty"`
}

PlanEntry is one manifest to build: a channel, or a version of a component.

type Source

type Source struct {
	Folder string `json:"folder"`
	// Files is the URL this folder's files are published at, so a folder
	// several manifests layer, such as the base game files, can be uploaded
	// once and shared. It overrides the entry's Files.
	Files string `json:"files,omitempty"`
}

Source is a folder of game files. In JSON it is the folder's path, or {"folder": ..., "files": ...} to publish its files at their own URL.

func (*Source) UnmarshalJSON

func (s *Source) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts a folder's path, or an object naming the folder and where its files are published.

type Sources

type Sources []Source

Sources is one folder, or several layered in order: where two hold the same file, the later one's is used. In JSON it is a source or a list of them.

func (*Sources) UnmarshalJSON

func (s *Sources) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts a source or a list of sources.

Jump to

Keyboard shortcuts

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