iofmt

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Overview

Package iofmt contains various IO utilities used for formatting output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LineWriter added in v0.0.11

func LineWriter(w io.Writer) io.WriteCloser

LineWriter returns an io.WriteCloser that only calls w.Write with complete lines. This can be used to make it less likely (without locks) for lines to interleave, for example if you are concurrently writing lines of text to os.Stdout. This is particularly useful when composed with PrefixWriter.

 // Full lines will be written to os.Stdout, so they will be less likely to
 // be interleaved with other output.
 linew := LineWriter(os.Stdout)
 defer func() {
		_ = linew.Close() // Handle the possible error.
 }()
 w := PrefixWriter(linew, "my-prefix: ")

Close will write any remaining partial line to the underlying writer.

func PrefixWriter

func PrefixWriter(w io.Writer, prefix string) io.Writer

PrefixWriter returns a new io.Writer that copies its writes to the provided io.Writer, adding a prefix at the beginning of each line.

Types

This section is empty.

Jump to

Keyboard shortcuts

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