Documentation
¶
Overview ¶
Package util contains useful components for simplifying Go code.
The package contains common error types (errors.go) and functions for converting arrays to pointers.
Index ¶
- Variables
- func CheckValidLength(expected, actual int) error
- func Index(inVal int64, inArray []int64) (index int, ok bool)
- func Lookup(inVal int64, inArray, outArray []int64) (outVal int64, ok bool)
- func MinInt(a, b int) int
- func MinInt64(a, b int64) int64
- func NeverError(err error)
- func Ptr(slice []byte) unsafe.Pointer
- func TestPath() (string, error)
- type ErrReader
- type ErrWriter
- type SystemError
Constants ¶
This section is empty.
Variables ¶
var TestEnvVarName = "TEST_FILESYSTEM_ROOT"
TestEnvVarName is the name on an environment variable that should be set to an empty mountpoint. This is only used for integration tests.
Functions ¶
func CheckValidLength ¶
CheckValidLength returns an invalid length error if expected != actual
func Index ¶
Index returns the first index i such that inVal == inArray[i]. ok is true if we find a match, false otherwise.
func Lookup ¶
Lookup finds inVal in inArray and returns the corresponding element in outArray. Specifically, if inVal == inArray[i], outVal == outArray[i]. ok is true if we find a match, false otherwise.
func NeverError ¶
func NeverError(err error)
NeverError panics if a non-nil error is passed in. It should be used to check for logic errors, not to handle recoverable errors.
Types ¶
type ErrReader ¶
type ErrReader struct {
// contains filtered or unexported fields
}
ErrReader wraps an io.Reader, passing along calls to Read() until a read fails. Then, the error is stored, and all subsequent calls to Read() do nothing. This allows you to write code which has many subsequent reads and do all of the error checking at the end. For example:
r := NewErrReader(reader)
r.Read(foo)
r.Read(bar)
r.Read(baz)
if r.Err() != nil {
// Handle error
}
Taken from https://blog.golang.org/errors-are-values by Rob Pike.
func NewErrReader ¶
NewErrReader creates an ErrReader which wraps the provided reader.
type ErrWriter ¶
type ErrWriter struct {
// contains filtered or unexported fields
}
ErrWriter works exactly like ErrReader, except with io.Writer.
func NewErrWriter ¶
NewErrWriter creates an ErrWriter which wraps the provided reader.
type SystemError ¶
type SystemError string
SystemError is an error that should indicate something has gone wrong in the underlying system (syscall failure, bad ioctl, etc...).
func (SystemError) Error ¶
func (s SystemError) Error() string