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 ¶
- func JSON(w io.Writer, statuses []rung.Status) error
- func Table(w io.Writer, statuses []rung.Status) error
- type Console
- func (c *Console) Applied(m rung.Migration)
- func (c *Console) Applying(m rung.Migration)
- func (c *Console) Blank()
- func (c *Console) Error(icon, format string, a ...any)
- func (c *Console) Info(icon, format string, a ...any)
- func (c *Console) Printf(format string, a ...any)
- func (c *Console) RolledBack(m rung.Migration)
- func (c *Console) RollingBack(m rung.Migration)
- func (c *Console) Skipped(m rung.Migration)
- func (c *Console) StoppedAtTarget(target, next int)
- func (c *Console) Success(icon, format string, a ...any)
- func (c *Console) Warn(icon, format string, a ...any)
- func (c *Console) Writer() io.Writer
- type Nop
- type Slog
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
NewConsole returns a Console writing to out, with colour and emoji enabled. A nil out means os.Stdout.
func NewPlain ¶
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 ¶
Applied implements rung.Reporter.
func (*Console) Applying ¶
Applying implements rung.Reporter.
func (*Console) RolledBack ¶
RolledBack implements rung.Reporter.
func (*Console) RollingBack ¶
RollingBack implements rung.Reporter.
func (*Console) Skipped ¶
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 ¶
StoppedAtTarget implements rung.Reporter.
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) RollingBack ¶
RollingBack implements rung.Reporter.
func (Nop) StoppedAtTarget ¶
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) RolledBack ¶
RolledBack implements rung.Reporter.
func (Slog) RollingBack ¶
RollingBack implements rung.Reporter.
func (Slog) Skipped ¶
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 ¶
StoppedAtTarget implements rung.Reporter.