lib

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const MaxInt64 = int64(MaxUint64 >> 1)
View Source
const MaxUint64 = ^uint64(0)

Variables

This section is empty.

Functions

func AddAndClamp

func AddAndClamp(a uint64, b int64, min uint64, max uint64) uint64

AddAndClamp calculates `a + b` in an overflow-proof manner, and ensures that the result is between `[min, max]`.

func CopyBoolPtr

func CopyBoolPtr(ptr *bool) *bool

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

func DerefBoolPtrWithDefault(ptr *bool, defaultValue bool) bool

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

func NewBoolPtr(val bool) *bool

NewBoolPtr allows creating a bool pointer in 1 line.

Before:

var val = true
doSomething(&val)

After:

doSomething(lib.NewBoolPtr(1))

func NewStringPtr

func NewStringPtr(val string) *string

NewStringPtr allows creating a string pointer in 1 line.

Before:

var data = "hello"
doSomething(&data)

After:

doSomething(lib.NewStringPtr("hello"))

func NewUint32Ptr

func NewUint32Ptr(val uint32) *uint32

NewUint32Ptr allows creating a uint32 pointer in 1 line.

Before:

var versionNumber uint32 = 1
doSomething(&versionNumber)

After:

doSomething(lib.NewUint32Ptr(1))

func NonEmptyStringOrNil

func NonEmptyStringOrNil(value string) *string

func ReflectMakeValPtr

func ReflectMakeValPtr(val reflect.Value) reflect.Value

ReflectMakeValPtr returns a `Reflect.Value` that's a pointer to the given value.

ReflectMakeValPtr(int(0)) // => *int

func UserConfigDir

func UserConfigDir() (string, error)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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