msg

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package msg holds the text Zelie shows people, in a form the web interface can translate. Each message is defined once, with a code and its English text. The web interface's English strings for these codes are generated from the definitions (see TestLocale), and other languages translate the codes. The English text also goes along with every message, for logs and for a language that lacks a code.

Index

Constants

This section is empty.

Variables

View Source
var Other = Define(0, "other.detail", "{detail}")

Other carries text Zelie did not write, such as a tool's error output. It is shown as it is, in every language.

Functions

This section is empty.

Types

type Error

type Error struct {
	Status int
	Msg
}

Error is a message given as an error, with the HTTP status that goes with it.

func (*Error) Error

func (e *Error) Error() string

func (*Error) WithStatus

func (e *Error) WithStatus(status int) *Error

WithStatus sends the error with another HTTP status, for a message that fits more than one case.

type Msg

type Msg struct {
	Code   string         `json:"code"`
	Params map[string]any `json:"params,omitempty"`
	Text   string         `json:"text"`
}

Msg is one message: its code, the values of its placeholders and its English text.

func Wrap

func Wrap(err error) Msg

Wrap gives any error a message: its own, if it has one, or Other.

type Template

type Template struct {
	Code    string
	English string
	// Status is the HTTP status an error with this message is sent with,
	// or 0 for a message that is only shown, never sent as an error.
	Status int
}

Template is a message as defined: {name} marks a value filled in later.

func All

func All() []Template

All returns every message defined so far, by code.

func Define

func Define(status int, code, english string) Template

Define declares a message. It is called from package variables, so a code defined twice or a malformed one stops the program at start.

func (Template) Err

func (t Template) Err(pairs ...any) *Error

Err makes the message into an error.

func (Template) Names

func (t Template) Names() []string

Names returns the placeholders in a message's English text.

func (Template) With

func (t Template) With(pairs ...any) Msg

With fills the placeholders from name, value pairs. Values stay what they are, so a translation can pick the plural form for a number.

Jump to

Keyboard shortcuts

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