Help us shape the future of Go! Take the 2026 Go Developer Survey

respfmt

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package respfmt produces human-readable, styled renderings of game server responses. It exists so multiple CLIs (play_as, bulk-buy-order, future tools) can present command output the same way without each re-implementing the same struct unmarshal + table layout logic.

Public surface

  • Format(command, raw, opts...) — dispatch by command name, return the styled rendering or "" if no formatter is registered.
  • Error(err, command) — friendly one-line error rendering, including command-specific overrides (e.g. mine "depleted" → "Ore depleted.").
  • Per-command exports (Storage, Market, …) for callers that already know exactly which renderer they want.

Scope

respfmt only produces styled output. Raw/JSON pass-through belongs in the caller. respfmt does not perform any I/O, network calls, or read from process state — every input is supplied via the function arguments.

Migration

Formatters are being moved from cmd/tools/play_as/main.go in stages. The package is intentionally small at first; expect the surface to grow as each migration lands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateBuyOrder

func CreateBuyOrder(raw []byte) string

CreateBuyOrder renders the action_result body of a create_buy_order command, listing failures explicitly. Returns "" if raw can't be parsed as the bulk-mode shape.

The accepted shapes are either the bare result body or the full action_result frame ({"command":..., "result":{...}}).

func CreateSellOrder

func CreateSellOrder(raw []byte) string

CreateSellOrder mirrors CreateBuyOrder for sell-side orders.

func Error

func Error(err error, command string) string

Error renders err as a single styled line.

If a (command, substring) pair in the override table matches, the friendly message is returned. Otherwise the raw error text is prefixed with "Error: ".

Callers that need transport-level context (e.g. "we're reconnecting, retry in a moment") should wrap this — Error makes no assumption about connection state. err must be non-nil; passing nil returns "".

func Format

func Format(command string, raw []byte, opts ...Option) string

Format dispatches command to the matching formatter and returns the styled rendering. Returns "" if no formatter is registered for command, letting callers fall back to JSON pretty-print.

Formatters are added incrementally as they migrate from play_as.

Types

type Option

type Option func(*options)

Option configures a Format call. Reserved for per-command toggles that would otherwise need package-level state — e.g. a future WithFullDescriptions() to replace play_as's missionsShowFull bool.

func WithFullDescriptions

func WithFullDescriptions() Option

WithFullDescriptions disables description truncation in formatters that would otherwise cap long bodies (e.g. missions).

Jump to

Keyboard shortcuts

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