Documentation ¶
Overview ¶
Package utils exports few handy functions
Index ¶
- func AddCloser(w io.Writer) io.WriteCloser
- func BreakInIndexes(id *types.ObjectID, start, end, partSize uint64) []*types.ObjectIndex
- func CopyN(w io.Writer, r io.Reader, limit int64) (n int64, err error)
- func CopyStringSlice(from []string) []string
- func FileExists(filePath string) bool
- func IsMetadataFresh(obj *types.ObjectMetadata) bool
- func LimitReadCloser(readCloser io.ReadCloser, max int64) io.ReadCloser
- func MultiReadCloser(readerClosers ...io.ReadCloser) io.ReadCloser
- func MultiWriteCloser(writers ...io.WriteCloser) io.WriteCloser
- func NewCompositeError(errors ...error) error
- func NewErrorWithStack(msg string) error
- func NopCloser(w io.Writer) io.WriteCloser
- func ProjectPath() (string, error)
- func SafeExecute(f func(), print func(error))
- func ShowContextOfJSONError(err error, jsonContents []byte) error
- func SkipReadCloser(readCloser io.ReadCloser, skip int64) (result io.ReadCloser, err error)
- func WrapErrorWithStack(err error) error
- type CompositeError
- type ErrorWithStack
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 CopyStringSlice ¶
CopyStringSlice deeply copies a slice of strings
func FileExists ¶
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 ¶
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
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 ¶
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
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
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