render

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package render turns migration progress and status into output.

It exists so that the engine in the parent package reports events without deciding how they look. A Console writes prose for a person, Slog writes structured records for a service log, and Nop discards everything.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSON

func JSON(w io.Writer, statuses []rung.Status) error

JSON writes the migration status as an indented JSON array, for scripts.

An empty status list encodes as [] rather than null, so a consumer can index the result without a nil check.

func Table

func Table(w io.Writer, statuses []rung.Status) error

Table writes the migration status table.

The format is a compatibility contract, not a presentation choice: it appears in deploy logs that people read and in scripts that grep them, so it is kept exactly as it is.

Types

type Console

type Console struct {
	// Out receives all output. Defaults to os.Stdout.
	Out io.Writer
	// NoColor suppresses ANSI colour even on a terminal.
	NoColor bool
	// NoEmoji suppresses the leading icons.
	NoEmoji bool
	// Verbose additionally reports migrations skipped as already applied.
	Verbose bool
}

Console reports progress as prose, with optional colour and emoji.

The zero value is usable and writes decorated output to os.Stdout. Colour is additionally suppressed by the fatih/color package whenever the destination is not a terminal, which is what makes the same output readable in a terminal and in a CI log.

func NewConsole

func NewConsole(out io.Writer) *Console

NewConsole returns a Console writing to out, with colour and emoji enabled. A nil out means os.Stdout.

func NewPlain

func NewPlain(out io.Writer) *Console

NewPlain returns a Console writing to out with colour and emoji disabled. The wording is identical to NewConsole. A nil out means os.Stdout.

func (*Console) Applied

func (c *Console) Applied(m rung.Migration)

Applied implements rung.Reporter.

func (*Console) Applying

func (c *Console) Applying(m rung.Migration)

Applying implements rung.Reporter.

func (*Console) Blank

func (c *Console) Blank()

Blank writes an empty line.

func (*Console) Error

func (c *Console) Error(icon, format string, a ...any)

Error writes a line reporting a failure.

func (*Console) Info

func (c *Console) Info(icon, format string, a ...any)

Info writes an informational line, such as a step beginning.

func (*Console) Printf

func (c *Console) Printf(format string, a ...any)

Printf writes undecorated text exactly as given.

func (*Console) RolledBack

func (c *Console) RolledBack(m rung.Migration)

RolledBack implements rung.Reporter.

func (*Console) RollingBack

func (c *Console) RollingBack(m rung.Migration)

RollingBack implements rung.Reporter.

func (*Console) Skipped

func (c *Console) Skipped(m rung.Migration)

Skipped implements rung.Reporter. It writes nothing unless Verbose is set, because reporting every previously applied migration on every run buries the ones that did something.

func (*Console) StoppedAtTarget

func (c *Console) StoppedAtTarget(target, next int)

StoppedAtTarget implements rung.Reporter.

func (*Console) Success

func (c *Console) Success(icon, format string, a ...any)

Success writes a line reporting that something completed.

func (*Console) Warn

func (c *Console) Warn(icon, format string, a ...any)

Warn writes a line drawing attention to a consequence.

func (*Console) Writer

func (c *Console) Writer() io.Writer

Writer returns the destination all output is written to, resolving a nil Out to os.Stdout. It is exported so that callers can direct other output, such as a status table, to the same place.

type Nop

type Nop struct{}

Nop discards every event. It is useful in tests and in programs that report progress some other way.

func (Nop) Applied

func (Nop) Applied(rung.Migration)

Applied implements rung.Reporter.

func (Nop) Applying

func (Nop) Applying(rung.Migration)

Applying implements rung.Reporter.

func (Nop) RolledBack

func (Nop) RolledBack(rung.Migration)

RolledBack implements rung.Reporter.

func (Nop) RollingBack

func (Nop) RollingBack(rung.Migration)

RollingBack implements rung.Reporter.

func (Nop) Skipped

func (Nop) Skipped(rung.Migration)

Skipped implements rung.Reporter.

func (Nop) StoppedAtTarget

func (Nop) StoppedAtTarget(int, int)

StoppedAtTarget implements rung.Reporter.

type Slog

type Slog struct {
	// Logger receives the records. A nil Logger means slog.Default().
	Logger *slog.Logger
}

Slog reports progress as structured log records.

It suits a program whose output is parsed rather than read -- a server applying migrations at startup in a development environment, or a job whose logs are shipped to an aggregator. For a command somebody runs and watches, prefer Console.

func (Slog) Applied

func (s Slog) Applied(m rung.Migration)

Applied implements rung.Reporter.

func (Slog) Applying

func (s Slog) Applying(m rung.Migration)

Applying implements rung.Reporter.

func (Slog) RolledBack

func (s Slog) RolledBack(m rung.Migration)

RolledBack implements rung.Reporter.

func (Slog) RollingBack

func (s Slog) RollingBack(m rung.Migration)

RollingBack implements rung.Reporter.

func (Slog) Skipped

func (s Slog) Skipped(m rung.Migration)

Skipped implements rung.Reporter. It logs at debug level, because a previously applied migration is the ordinary case on every run after the first.

func (Slog) StoppedAtTarget

func (s Slog) StoppedAtTarget(target, next int)

StoppedAtTarget implements rung.Reporter.

Jump to

Keyboard shortcuts

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