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 AtoiOrPanic(input string) int
- func ByteSlice(ptr unsafe.Pointer) []byte
- func CheckValidLength(expected, actual int) error
- func EffectiveUser() (*user.User, error)
- func Index(inVal int64, inArray []int64) (index int, ok bool)
- func IsUserRoot() bool
- func Lookup(inVal int64, inArray, outArray []int64) (outVal int64, ok bool)
- func MaxInt(a, b int) int
- func MinInt(a, b int) int
- func MinInt64(a, b int64) int64
- func NeverError(err error)
- func PointerSlice(ptr unsafe.Pointer) []unsafe.Pointer
- func Ptr(slice []byte) unsafe.Pointer
- func ReadLine() (string, error)
- func TestRoot() (string, error)
- type ErrReader
- type ErrWriter
- type SystemError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSkipIntegration indicates integration tests shouldn't be run. ErrSkipIntegration = errors.New("skipping integration test") )
Functions ¶
func AtoiOrPanic ¶ added in v0.2.1
AtoiOrPanic converts a string to an int or it panics. Should only be used in situations where the input MUST be a decimal number.
func ByteSlice ¶ added in v0.2.0
ByteSlice takes a pointer to some data and views it as a slice of bytes. Note, indexing into this slice is unsafe.
func CheckValidLength ¶
CheckValidLength returns an invalid length error if expected != actual
func EffectiveUser ¶ added in v0.2.1
EffectiveUser returns the user entry corresponding to the effective user.
func Index ¶
Index returns the first index i such that inVal == inArray[i]. ok is true if we find a match, false otherwise.
func IsUserRoot ¶ added in v0.2.1
func IsUserRoot() bool
IsUserRoot checks if the effective user is root.
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.
func PointerSlice ¶ added in v0.2.0
PointerSlice takes a pointer to an array of pointers and views it as a slice of pointers. Note, indexing into this slice is unsafe.
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