objutil

package
v0.0.0-...-c5d0b2b Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2017 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UintMax is the maximum value of a uint.
	UintMax = ^uint(0)

	// UintMin is the minimum value of a uint.
	UintMin = 0

	// Uint8Max is the maximum value of a uint8.
	Uint8Max = 255

	// Uint8Min is the minimum value of a uint8.
	Uint8Min = 0

	// Uint16Max is the maximum value of a uint16.
	Uint16Max = 65535

	// Uint16Min is the minimum value of a uint16.
	Uint16Min = 0

	// Uint32Max is the maximum value of a uint32.
	Uint32Max = 4294967295

	// Uint32Min is the minimum value of a uint32.
	Uint32Min = 0

	// Uint64Max is the maximum value of a uint64.
	Uint64Max = 18446744073709551615

	// Uint64Min is the minimum value of a uint64.
	Uint64Min = 0

	// UintptrMax is the maximum value of a uintptr.
	UintptrMax = ^uintptr(0)

	// UintptrMin is the minimum value of a uintptr.
	UintptrMin = 0

	// IntMax is the maximum value of a int.
	IntMax = int(UintMax >> 1)

	// IntMin is the minimum value of a int.
	IntMin = -IntMax - 1

	// Int8Max is the maximum value of a int8.
	Int8Max = 127

	// Int8Min is the minimum value of a int8.
	Int8Min = -128

	// Int16Max is the maximum value of a int16.
	Int16Max = 32767

	// Int16Min is the minimum value of a int16.
	Int16Min = -32768

	// Int32Max is the maximum value of a int32.
	Int32Max = 2147483647

	// Int32Min is the minimum value of a int32.
	Int32Min = -2147483648

	// Int64Max is the maximum value of a int64.
	Int64Max = 9223372036854775807

	// Int64Min is the minimum value of a int64.
	Int64Min = -9223372036854775808

	// Float32IntMax is the maximum consecutive integer value representable by a float32.
	Float32IntMax = 16777216

	// Float32IntMin is the minimum consecutive integer value representable by a float32.
	Float32IntMin = -16777216

	// Float64IntMax is the maximum consecutive integer value representable by a float64.
	Float64IntMax = 9007199254740992

	// Float64IntMin is the minimum consecutive integer value representable by a float64.
	Float64IntMin = -9007199254740992
)

Variables

This section is empty.

Functions

func AppendDuration

func AppendDuration(b []byte, d time.Duration) []byte

AppendDuration appends a human-readable representation of d to b.

The function copies the implementation of time.Duration.String but prevents Go from making a dynamic memory allocation on the returned value.

func CheckInt64Bounds

func CheckInt64Bounds(v int64, min int64, max uint64, t reflect.Type) (err error)

CheckInt64Bounds verifies that v is within min and max, t represents the original type of v.

func CheckUint64Bounds

func CheckUint64Bounds(v uint64, max uint64, t reflect.Type) (err error)

CheckUint64Bounds verifies that v is smaller than max, t represents the original type of v.

func IsEmpty

func IsEmpty(v interface{}) bool

IsEmpty returns true if the value given as argument would be considered empty by the standard library packages, and therefore not serialized if `omitempty` is set on a struct field with this value.

func IsEmptyValue

func IsEmptyValue(v reflect.Value) bool

IsEmptyValue returns true if the value given as argument would be considered empty by the standard library packages, and therefore not serialized if `omitempty` is set on a struct field with this value.

Based on https://golang.org/src/encoding/json/encode.go?h=isEmpty

func IsZero

func IsZero(v interface{}) bool

IsZero returns true if the value given as argument is the zero-value of the type of v.

func IsZeroValue

func IsZeroValue(v reflect.Value) bool

func ParseInt

func ParseInt(b []byte) (int64, error)

ParseInt parses a decimanl representation of an int64 from b.

The function is equivalent to calling strconv.ParseInt(string(b), 10, 64) but it prevents Go from making a memory allocation for converting a byte slice to a string (escape analysis fails due to the error returned by strconv.ParseInt).

Because it only works with base 10 the function is also significantly faster than strconv.ParseInt.

func ParseUintHex

func ParseUintHex(b []byte) (uint64, error)

ParseUintHex parses a hexadecimanl representation of a uint64 from b.

The function is equivalent to calling strconv.ParseUint(string(b), 16, 64) but it prevents Go from making a memory allocation for converting a byte slice to a string (escape analysis fails due to the error returned by strconv.ParseUint).

Because it only works with base 16 the function is also significantly faster than strconv.ParseUint.

Types

type Tag

type Tag struct {
	// Name is the field name that should be used when serializing.
	Name string

	// Omitempty is true if the tag had `omitempty` set.
	Omitempty bool

	// Omitzero is true if the tag had `omitzero` set.
	Omitzero bool
}

Tag represents the result of parsing the tag of a struct field.

func ParseTag

func ParseTag(s string) Tag

ParseTag parses a raw tag obtained from a struct field, returning the results as a tag value.

Jump to

Keyboard shortcuts

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