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

util

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option added in v0.0.6

type Option func(*options)

Option configures RedirectStdToFiles / RedirectStdToFilesIn.

func TapStderr added in v0.0.6

func TapStderr(tap func(line string)) Option

TapStderr is TapStdout for stderr.

func TapStdout added in v0.0.6

func TapStdout(tap func(line string)) Option

TapStdout adds a live copy of every line written to stdout. An app that owns the terminal itself, like a tui, can use it to show the output of the standard logger and of libraries printing to stdout instead of only finding it in the file after the run.

The tap is called from a reader goroutine, with the line stripped of its newline, and must not print to stdout itself, which would feed straight back into it. Restore waits until everything written before it has been passed on.

type RestoreSTD

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

func RedirectStdToFiles

func RedirectStdToFiles(opts ...Option) (*RestoreSTD, error)

RedirectStdToFiles replaces stdout and stderr with file writers in the working directory. The returned struct has functions to revert replacement of stdout and err with fs files.

func RedirectStdToFilesIn added in v0.0.2

func RedirectStdToFilesIn(dir string, opts ...Option) (*RestoreSTD, error)

RedirectStdToFilesIn is RedirectStdToFiles writing into dir, which is created if it does not exist. An app that already has a place for its scratch files can keep the logs there instead of dropping them wherever it was started.

func (*RestoreSTD) AddCallback

func (r *RestoreSTD) AddCallback(f func())

func (*RestoreSTD) Restore

func (r *RestoreSTD) Restore()

Restore puts the real stdout and stderr back. The order matters, the pipes are closed only once nothing can write to them any more, and the files only once the readers have drained what was still in flight.

func (*RestoreSTD) Run

func (r *RestoreSTD) Run(f func())

Jump to

Keyboard shortcuts

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