prefixw

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: MIT Imports: 3 Imported by: 6

README

koron-go/prefixw - prefix writer

GoDoc Actions/Go Go Report Card

A io.Writer appends prefix for each lines.

import "github.com/koron-go/prefixw"
import "os"

func main() {
    w := prefixw.New(os.Stdout, "[PREFIX] ")
    w.Write([]byte("Hello\nWorld\n"))

    // Output:
    // [PREFIX] Hello
    // [PREFIX] World
}

Documentation

Overview

Package prefixw provides a writer which puts prefix each lines.

Example
package main

import (
	"os"

	"github.com/koron-go/prefixw"
)

func main() {
	w := prefixw.New(os.Stdout, "PREFIX ")
	w.Write([]byte("Hello\nWorld\n"))

}
Output:

PREFIX Hello
PREFIX World

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Writer

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

Writer implements io.Writer with prefix each lines.

func New

func New(w io.Writer, prefix string) *Writer

New creates a new prefix Writer.

func (*Writer) Close

func (w *Writer) Close() error

Close flushes buffered data and closes Writer.

Example
package main

import (
	"os"

	"github.com/koron-go/prefixw"
)

func main() {
	w1 := prefixw.New(os.Stdout, "PREFIX1 ")
	w1.Write([]byte("Hello\nSufficient\nWorld"))
	w1.Close()

	w2 := prefixw.New(os.Stdout, "PREFIX2 ")
	w2.Write([]byte("Hello\nInsufficient\nWorld"))

}
Output:

PREFIX1 Hello
PREFIX1 Sufficient
PREFIX1 World
PREFIX2 Hello
PREFIX2 Insufficient

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write writes data to base Writer with prefix.

Example
package main

import (
	"os"

	"github.com/koron-go/prefixw"
)

func main() {
	w1 := prefixw.New(os.Stdout, "PREFIX1 ")
	w1.Write([]byte("Hello\nSufficient"))
	w1.Write([]byte("World\n"))

	w2 := prefixw.New(os.Stdout, "PREFIX2 ")
	w2.Write([]byte("Hello\nInsufficient"))
	w2.Write([]byte("World"))

}
Output:

PREFIX1 Hello
PREFIX1 SufficientWorld
PREFIX2 Hello

Jump to

Keyboard shortcuts

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