stdio

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 6 Imported by: 2

README

Stdio

stdio provide some standard IO util functions.

Install

go get github.com/gookit/goutil/x/stdio

Go docs

Usage

Please see tests.

Testings

go test -v ./stdio/...

Test limit by regexp:

go test -v -run ^TestSetByKeys ./stdio/...

Documentation

Overview

Package stdio provide some standard IO util functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscardReader

func DiscardReader(src io.Reader)

DiscardReader anything from the reader

func Fprint

func Fprint(w io.Writer, a ...any)

Fprint to writer, will ignore error

func Fprintf

func Fprintf(w io.Writer, tpl string, vs ...any)

Fprintf to writer, will ignore error

func Fprintln

func Fprintln(w io.Writer, a ...any)

Fprintln to writer, will ignore error

func MustReadReader

func MustReadReader(r io.Reader) []byte

MustReadReader read contents from io.Reader, will panic on error

func NewIOReader

func NewIOReader(in any) io.Reader

NewIOReader instance by input: string, bytes, io.Reader

func NewScanner

func NewScanner(in any) *bufio.Scanner

NewScanner instance by input data or reader

func ReadString

func ReadString(r io.Reader) string

ReadString read contents from io.Reader, return empty string on error

func SafeClose added in v0.7.3

func SafeClose(c io.Closer)

SafeClose close io.Closer, ignore error

func WriteByte

func WriteByte(b byte)

WriteByte to stdout, will ignore error

func WriteBytes

func WriteBytes(bs []byte)

WriteBytes to stdout, will ignore error

func WriteString

func WriteString(s string)

WriteString to stdout. will ignore error

func WriteStringTo

func WriteStringTo(w io.Writer, ss ...string)

WriteStringTo a writer, will ignore error

func Writeln

func Writeln(s string)

Writeln string to stdout. will ignore error

func WritelnBytes

func WritelnBytes(bs []byte)

WritelnBytes to stdout, will ignore error

Types

type FlushCloseWriter

type FlushCloseWriter interface {
	Flusher
	// WriteCloser the output writer
	io.WriteCloser
}

FlushCloseWriter is the interface satisfied by logging destinations.

type FlushWriter

type FlushWriter interface {
	Flusher
	// Writer the output writer
	io.Writer
}

FlushWriter is the interface satisfied by logging destinations.

type Flusher

type Flusher interface {
	Flush() error
}

Flusher interface

type SyncCloseWriter

type SyncCloseWriter interface {
	Syncer
	// WriteCloser the output writer
	io.WriteCloser
}

SyncCloseWriter is the interface satisfied by logging destinations. such as os.File

type Syncer

type Syncer interface {
	Sync() error
}

Syncer interface

type WriteWrapper

type WriteWrapper struct {
	Out io.Writer
}

WriteWrapper warp io.Writer support more operate methods.

func NewWriteWrapper

func NewWriteWrapper(w io.Writer) *WriteWrapper

NewWriteWrapper instance

func WrapW

func WrapW(w io.Writer) *WriteWrapper

WrapW instance

func (*WriteWrapper) String

func (w *WriteWrapper) String() string

String get write data string

func (*WriteWrapper) Write

func (w *WriteWrapper) Write(p []byte) (n int, err error)

Write bytes data

func (*WriteWrapper) WriteByte

func (w *WriteWrapper) WriteByte(c byte) error

WriteByte data

func (*WriteWrapper) WriteString

func (w *WriteWrapper) WriteString(s string) (n int, err error)

WriteString data

func (*WriteWrapper) Writef

func (w *WriteWrapper) Writef(tpl string, vs ...any) (n int, err error)

Writef data to output

Jump to

Keyboard shortcuts

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