Documentation ¶
Overview ¶
The `ref` package supplies a way for Go code to create references to literals or other expressions that would typically require a variable declaration. This simplifies expressions, particularly struct initializations.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func String ¶
String returns a reference to the value passed as a parameter.
Example ¶
package main import ( "fmt" "github.com/cultureamp/ca-go/ref" ) type ExampleType struct { Member *string } func main() { val := "value1" ex1 := ExampleType{ Member: &val, } ex2 := ExampleType{ Member: ref.String("value2"), } fmt.Printf("%s %s\n", *ex1.Member, *ex2.Member) }
Output: value1 value2
func Strings ¶
Strings returns a new array of pointers that has the same length as the supplied array, and whose elements contain pointers to strings in the equivalent indexes from the supplied array.
func ToStruct ¶
func ToStruct(ptr interface{}) interface{}
ToStruct returns a reference representing the value of the supplied pointer. So if *a{} is supplied, a{} will be returned.
func ToStructPointer ¶
func ToStructPointer(a interface{}) interface{}
ToStructPointer creates an interface{} instance that is a pointer to the underlying struct value of the supplied instance of interface{}. So if a{} is supplied, this will return &a{}.
Types ¶
This section is empty.