utils

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: May 27, 2016 License: GPL-3.0 Imports: 14 Imported by: 14

Documentation

Overview

Package utils exports few handy functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCloser added in v0.1.5

func AddCloser(w io.Writer) io.WriteCloser

AddCloser adds io.Closer to a io.Writer. If the provided io.Writer is io.WriteCloser it's just casted, otherwise a NopCloser is used

func BreakInIndexes

func BreakInIndexes(id *types.ObjectID, start, end, partSize uint64) []*types.ObjectIndex

BreakInIndexes returns a slice of ObjectIndexes according to the specified byte range [start, end] (inclusive).

func CopyN added in v0.1.9

func CopyN(w io.Writer, r io.Reader, limit int64) (n int64, err error)

CopyN uses io.CopyN but tries to only have ONE io.LimitReader

func CopyStringSlice

func CopyStringSlice(from []string) []string

CopyStringSlice deeply copies a slice of strings

func FileExists

func FileExists(filePath string) bool

FileExists returns true if filePath is already existing regular file. If it is a directory FileExists will return false.

func IsMetadataFresh

func IsMetadataFresh(obj *types.ObjectMetadata) bool

IsMetadataFresh checks whether the supplied metadata could still be used.

func LimitReadCloser

func LimitReadCloser(readCloser io.ReadCloser, max int64) io.ReadCloser

LimitReadCloser wraps a io.ReadCloser but stops with EOF after `max` bytes.

func MultiReadCloser

func MultiReadCloser(readerClosers ...io.ReadCloser) io.ReadCloser

MultiReadCloser returns a io.ReadCloser that's the logical concatenation of the provided input readers.

func MultiWriteCloser

func MultiWriteCloser(writers ...io.WriteCloser) io.WriteCloser

MultiWriteCloser creates a writer that duplicates its writes to all the provided writers, similar to the Unix tee(1) command.

func NewCompositeError

func NewCompositeError(errors ...error) error

NewCompositeError returns a new CompositeError with the supplied errors. The error interface is returned because of this: https://golang.org/doc/faq#nil_error

func NewErrorWithStack added in v0.1.1

func NewErrorWithStack(msg string) error

NewErrorWithStack returns a new error with the current stack

func NopCloser

func NopCloser(w io.Writer) io.WriteCloser

NopCloser returns a WriteCloser with a no-op Close method wrapping the provided Writer w.

func ProjectPath

func ProjectPath() (string, error)

ProjectPath returns a path to the project source as an absolute directory name.

func SafeExecute added in v0.1.7

func SafeExecute(f func(), print func(error))

SafeExecute executes f and recovers from any panics inside it if panic is found it will be wrapped with NewErrorWithStack and used with the provided print func

func ShowContextOfJSONError added in v0.1.9

func ShowContextOfJSONError(err error, jsonContents []byte) error

ShowContextOfJSONError is utility function that wrap *json.SyntaxError in an error which shows the context of the error. If the error provided is not *json.SyntaxError it's returned as it is.

func SkipReadCloser

func SkipReadCloser(readCloser io.ReadCloser, skip int64) (result io.ReadCloser, err error)

SkipReadCloser wraps a io.ReadCloser and ignores the first `skip` bytes.

func WrapErrorWithStack added in v0.1.1

func WrapErrorWithStack(err error) error

WrapErrorWithStack returns an error with the current stack wrapping the provided one

Types

type CompositeError

type CompositeError []error

CompositeError is used for saving multiple errors. IMPORTANT: *NOT* safe for concurrent usage

func (*CompositeError) AppendError

func (c *CompositeError) AppendError(err error)

AppendError is used for adding another error to the list.

func (*CompositeError) Empty

func (c *CompositeError) Empty() bool

Empty returns true if the internal error list is empty.

func (*CompositeError) Error

func (c *CompositeError) Error() string

Returns a string representation of all errors in the order they were appended.

type ErrorWithStack added in v0.1.1

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

ErrorWithStack is an error which wraps around another error and records the current stack

func (*ErrorWithStack) Error added in v0.1.1

func (s *ErrorWithStack) Error() string

func (*ErrorWithStack) Original added in v0.1.1

func (s *ErrorWithStack) Original() error

Original returns the original error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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