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

redact

package
v4.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package redact is how the programs under scripts/ that drive a real instance print: through one Printer, which masks what a run can carry.

`gates transcript` forbids fmt.Print*, os.Stdout, os.Stderr, log and log/slog in every driver, which leaves Printer.write as the one place a line reaches a terminal. So a print that bypasses the masking is not something to remember; the gate refuses it.

The masking is the server's own (internal/redact): tokens, URLs with their hosts and namespace paths, addresses and application ids, with stable placeholders so a transcript still reads as a story — {host 1} in one result is {host 1} in the next. Secrets a job log can carry are masked on top. Values with no shape — the username the run signed in as, the scratch project's path — are registered with Known.

What it cannot hide: titles, bodies, comments and file contents. The live driver reads only the scratch project it created (docs/architecture.md §9.1), which is what keeps them harmless, and Summary says so on every run.

Index

Constants

View Source
const (
	KindHost = core.KindHost
	KindPath = core.KindPath
	KindUser = core.KindUser
	// KindID is a numeric id the run learned from the instance: the
	// scratch project's, a user's.
	KindID = core.KindID
)

Kinds a driver registers with Known. They are the server's, so a transcript and a doctor report name things the same way.

Variables

This section is empty.

Functions

func ID

func ID(id string) string

ID is the server's own truncation, so a report and a log line show the same key for the same id.

Types

type Printer

type Printer struct {
	// contains filtered or unexported fields
}

A Printer is the only way a driver writes anything.

func NewPrinter

func NewPrinter(red *Redactor) *Printer

NewPrinter writes the run to the terminal.

func NewPrinterTo

func NewPrinterTo(red *Redactor, out, err io.Writer) *Printer

NewPrinterTo writes somewhere else, which is how a test reads what a run would have printed.

func (*Printer) Fail

func (p *Printer) Fail(format string, args ...any)

Fail prints the run's own failure, to stderr.

func (*Printer) Redactor

func (p *Printer) Redactor() *Redactor

Redactor is the printer's redactor, for registering Known values.

func (*Printer) Say

func (p *Printer) Say(text string)

Say prints one line.

func (*Printer) Sayf

func (p *Printer) Sayf(format string, args ...any)

Sayf prints one formatted line. The whole formatted line is masked, not only the arguments somebody remembered to wrap.

func (*Printer) Summary

func (p *Printer) Summary()

Summary prints what was hidden and what could not be, to stderr.

type Redactor

type Redactor struct {
	// Off returns text unchanged. Only for a terminal nobody else sees.
	Off bool
	// contains filtered or unexported fields
}

A Redactor replaces instance-specific values with stable placeholders.

func NewRedactor

func NewRedactor(off bool) *Redactor

NewRedactor returns a redactor with nothing registered.

func (*Redactor) Do

func (r *Redactor) Do(text string) string

Do masks text. Secrets first, so a token inside a URL is one mask rather than half of one.

func (*Redactor) Known

func (r *Redactor) Known(kind, value string)

Known registers a value to mask wherever it appears as a whole word.

func (*Redactor) Summary

func (r *Redactor) Summary() string

Summary says what was hidden, and what cannot be.

Jump to

Keyboard shortcuts

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