package
1.4.57
Repository: https://github.com/borderzero/border0-go.git
Documentation: pkg.go.dev

# README

pointer

Go Report Card Documentation license

TL;DR smplifies dealing with pointers in Go...

In Go, taking the address of a literal (string, number, etc) is illegal because it has ambiguous semantics. This fact (and dealing with that ambiguity) often makes Go code longer than it needs to be.

For example, assume you have a struct with all pointer fields... To populate it, you'd have to first define all the values outside of the struct definition:

myString := "string"
myBool := true
myInt := 999

s := MyStruct{
    MyString: &myString,
    MyBool:   &myBool,
    MyInt:    &myInt,
}

Using this library, this can be simplified to:

s := MyStruct{
    MyString: pointer.To("string"),
    MyBool:   pointer.To(true),
    MyInt:    pointer.To(999),
}

# Functions

To returns the address of any given value.
ValueOrDefault returns the value of dereferencing a pointer if the pointer is not nil, or a given default value if nil.
ValueOrZero returns the value of dereferencing a pointer if the pointer is not nil, or the zero value of the type if nil.