Documentation ¶
Index ¶
- Constants
- func AddAndClamp(a uint64, b int64, min uint64, max uint64) uint64
- func CopyBoolPtr(ptr *bool) *bool
- func DerefBoolPtrWithDefault(ptr *bool, defaultValue bool) bool
- func NewBoolPtr(val bool) *bool
- func NewStringPtr(val string) *string
- func NewUint32Ptr(val uint32) *uint32
- func NonEmptyStringOrNil(value string) *string
- func ReflectMakeValPtr(val reflect.Value) reflect.Value
- func UserConfigDir() (string, error)
Constants ¶
const MaxInt64 = int64(MaxUint64 >> 1)
const MaxUint64 = ^uint64(0)
Variables ¶
This section is empty.
Functions ¶
func AddAndClamp ¶
AddAndClamp calculates `a + b` in an overflow-proof manner, and ensures that the result is between `[min, max]`.
func CopyBoolPtr ¶
CopyBoolPtr copies the value if the given boolean pointer into a new boolean pointer. If the pointer is nil, then it returns nil.
func DerefBoolPtrWithDefault ¶
DerefBoolPtrWithDefault dereferences the given pointer if it's non-nil, or returns the default value if it is nil.
It shortens code. Before:
if val == nil { doSomething(*val) } else { doSomething(true) }
After:
doSomething(DerefBoolPtrWithDefault(val, true))
func NewBoolPtr ¶
NewBoolPtr allows creating a bool pointer in 1 line.
Before:
var val = true doSomething(&val)
After:
doSomething(lib.NewBoolPtr(1))
func NewStringPtr ¶
NewStringPtr allows creating a string pointer in 1 line.
Before:
var data = "hello" doSomething(&data)
After:
doSomething(lib.NewStringPtr("hello"))
func NewUint32Ptr ¶
NewUint32Ptr allows creating a uint32 pointer in 1 line.
Before:
var versionNumber uint32 = 1 doSomething(&versionNumber)
After:
doSomething(lib.NewUint32Ptr(1))
func NonEmptyStringOrNil ¶
func ReflectMakeValPtr ¶
ReflectMakeValPtr returns a `Reflect.Value` that's a pointer to the given value.
ReflectMakeValPtr(int(0)) // => *int
func UserConfigDir ¶
UserConfigDir returns the default root directory to use for user-specific configuration data. Users should create their own application-specific subdirectory within this one and use that.
On Unix systems, it returns $XDG_CONFIG_HOME as specified by https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if non-empty, else $HOME/.config. On macOS, it returns $HOME/Library/Application Support. On Windows, it returns %AppData%. On Plan 9, it returns $home/lib.
If the location cannot be determined (for example, $HOME is not defined), then it will return an error.
The differences between this and `os.UserConfigDir` are:
- on macOS we return $XDG_CONFIG_HOME or ~/.config instead of ~/Library/Application Support.
- We determine the home directory through more than just $HOME, so we're resilient against cases in which $HOME is not set.
Types ¶
This section is empty.