printbuf

package module
v0.0.0-...-8fea7d1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2017 License: MIT Imports: 2 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type T

type T struct {
	*bytes.Buffer
}

Support buffered printing especially for error messages. This type implements the "error" interface allowing types that consume this one, as an anonymous field, to automatically project the public interface below easing the creation of a custom error type. A custom type coupled with a type assertion enables a swift and direct comparison mechanism to test for a specific error instead of inspecting the text of an errormessage.

Example

Define custom type called 'LoadFail':

type LoadFail struct {
	printbuf.T
}

Declare variable 'lf' based on 'LoadFail' custom type:

var lf LoadFail
lf.Sprintf("message")
...
var err error = lf;
...
if err.(LoadFail) {
	fmt.Fprintf(err.Error())
	//	output: "message"
}

Notes

* Currently not concurrency safe.

func (T) Error

func (pb T) Error() string

func (*T) Sprintf

func (pb *T) Sprintf(format string, args ...interface{})

func (*T) Sprintln

func (pb *T) Sprintln(a ...interface{})

Jump to

Keyboard shortcuts

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