utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RemoveFunc = os.RemoveAll

RemoveFunc is the function to remove dir

Functions

func CheckedClose

func CheckedClose(c io.Closer, err error) error

CheckedClose may be called on defer to properly close a resource and log any errors

func CleanUp

func CleanUp(dir string, err error) error

CleanUp temporary files

func Concat

func Concat(slices [][]byte) []byte

Concat conactenates a "list" of slices of type []byte

func ConcatErrChan

func ConcatErrChan(errChan <-chan error, expected int) error

ConcatErrChan concatenates all the errors in the channel into in a single error

func FilePathSansExt

func FilePathSansExt(path string) string

FilePathSansExt trims the extension from a file path

func FilePathTrailingJoin

func FilePathTrailingJoin(s ...string) string

FilePathTrailingJoin is like filepath.Join but ensures there is a trailing seprator

func NewNoNewlineWriter

func NewNoNewlineWriter(w io.Writer) io.Writer

NewNoNewlineWriter wrap a writer and filters out '\n' runes

func PathTrailingJoin

func PathTrailingJoin(s ...string) string

PathTrailingJoin is like path.Join but ensures there is a trailing seprator

func StripTrace

func StripTrace(e error) error

StripTrace cause the stack trace to not print on the error Not that it evaluates the Error() function

func Uint64ToPosInt

func Uint64ToPosInt(i uint64) (o int, err error)

Uint64ToPosInt convertes a uint64 to an int if it is positive as an int, returning an error otherwise

Types

type ConstReader

type ConstReader byte

ConstReader is a stream of a constant byte

func (ConstReader) Read

func (r ConstReader) Read(b []byte) (int, error)

type CounterWriter

type CounterWriter struct {
	io.Writer
	Count int
}

CounterWriter is a writer that counts the number bytes written to it

func (*CounterWriter) Write

func (cw *CounterWriter) Write(p []byte) (n int, err error)

type Error

type Error struct {
	HasStack bool
	// contains filtered or unexported fields
}

Error is an error type that may be used to turn off the stack trace

func NewError

func NewError(errtext string, hasStack bool) Error

NewError creates a new Error

func WrapError

func WrapError(err error, hasStack bool) Error

WrapError creates a new Error

func (Error) Error

func (e Error) Error() string

type Errors

type Errors []error

Errors holds mutiple errors

func (Errors) Error

func (es Errors) Error() string

type ResetReader

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

ResetReader is an io.Reader that reads from r and calls resetfn every time Read() is called

func NewResetReader

func NewResetReader(r io.Reader, f func()) *ResetReader

NewResetReader creates a new ResetReader that reads from r and calls resetfn every time Read() is called

func (*ResetReader) Read

func (trr *ResetReader) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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