ref

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 2 Imported by: 0

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 Bool

func Bool(i bool) *bool

Bool returns a reference to the value passed as a parameter.

func Duration

func Duration(i time.Duration) *time.Duration

Duration returns a reference to the value passed as a parameter.

func Int

func Int(i int) *int

Int returns a reference to the value passed as a parameter.

func Int64

func Int64(i int64) *int64

Int64 returns a reference to the value passed as a parameter.

func String

func String(i string) *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

func Strings(ss []string) []*string

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.

Jump to

Keyboard shortcuts

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