pointer

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: BSD-3-Clause Imports: 2 Imported by: 32

README

pointer

Go workflow status badge codecov Go Report Card GoDoc

Package pointer contains helper routines for simplifying the creation of optional fields of basic type.

A little copying is better than a little dependency

With the advent of generics in go 1.18, using this library in your code is likely to be unwarranted, I recommend that you make a small local copy of this library, for example:

Put the code below in the file: internal/pointer/pointer.go and use it at your own pleasure.

package pointer

// Of is a helper routine that allocates a new any value
// to store v and returns a pointer to it.
func Of[Value any](v Value) *Value {
    return &v
}

Installation

go get github.com/xorcare/pointer

Generics

Starting with Go 18+, you can use the Of method to get pointers to values of any types.

Examples

Examples of using the library are presented on godoc.org and in the source library code.

FAQ

Question Source
How to set bool pointer in a struct literal or variable? var _ *bool = pointer.Bool(true)
How to set byte pointer in a struct literal or variable? var _ *byte = pointer.Byte(1)
How to set complex64 pointer in a struct literal or variable? var _ *complex64 = pointer.Complex64(1.1)
How to set complex128 pointer in a struct literal or variable? var _ *complex128 = pointer.Complex128(1.1)
How to set float32 pointer in a struct literal or variable? var _ *float32 = pointer.Float32(1.1)
How to set float64 pointer in a struct literal or variable? var _ *float64 = pointer.Float64(1.1)
How to set int pointer in a struct literal or variable? var _ *int = pointer.Int(1)
How to set int8 pointer in a struct literal or variable? var _ *int8 = pointer.Int8(8)
How to set int16 pointer in a struct literal or variable? var _ *int16 = pointer.Int16(16)
How to set int32 pointer in a struct literal or variable? var _ *int32 = pointer.Int32(32)
How to set int64 pointer in a struct literal or variable? var _ *int64 = pointer.Int64(64)
How to set rune pointer in a struct literal or variable? var _ *rune = pointer.Rune(1)
How to set string pointer in a struct literal or variable? var _ *string = pointer.String("ptr")
How to set uint pointer in a struct literal or variable? var _ *uint = pointer.Uint(1)
How to set uint8 pointer in a struct literal or variable? var _ *uint8 = pointer.Uint8(8)
How to set uint16 pointer in a struct literal or variable? var _ *uint16 = pointer.Uint16(16)
How to set uint32 pointer in a struct literal or variable? var _ *uint32 = pointer.Uint32(32)
How to set uint64 pointer in a struct literal or variable? var _ *uint64 = pointer.Uint64(64)
How to set time.Time pointer in a struct literal or variable? var _ *time.Time = pointer.Time(time.Now())
How to set time.Duration pointer in a struct literal or variable? var _ *time.Duration = pointer.Duration(time.Hour)

License

© 2019-2020,2022 Vasiliy Vasilyuk xorcare@gmail.com

Released under the BSD 3-Clause License.

Documentation

Overview

Package pointer contains helper routines for simplifying the creation of optional fields of basic type.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any(v interface{}) interface{}

Any is a helper routine that allocates a new interface value to store v and returns a pointer to it.

// Usage: var _ *Type = pointer.Any(Type(value) | value).(*Type)

var _ *bool = pointer.Any(true).(*bool)
var _ *byte = pointer.Any(byte(1)).(*byte)
var _ *complex64 = pointer.Any(complex64(1.1)).(*complex64)
var _ *complex128 = pointer.Any(complex128(1.1)).(*complex128)
var _ *float32 = pointer.Any(float32(1.1)).(*float32)
var _ *float64 = pointer.Any(float64(1.1)).(*float64)
var _ *int = pointer.Any(int(1)).(*int)
var _ *int8 = pointer.Any(int8(8)).(*int8)
var _ *int16 = pointer.Any(int16(16)).(*int16)
var _ *int32 = pointer.Any(int32(32)).(*int32)
var _ *int64 = pointer.Any(int64(64)).(*int64)
var _ *rune = pointer.Any(rune(1)).(*rune)
var _ *string = pointer.Any("ptr").(*string)
var _ *uint = pointer.Any(uint(1)).(*uint)
var _ *uint8 = pointer.Any(uint8(8)).(*uint8)
var _ *uint16 = pointer.Any(uint16(16)).(*uint16)
var _ *uint32 = pointer.Any(uint32(32)).(*uint32)
var _ *uint64 = pointer.Any(uint64(64)).(*uint64)
var _ *uintptr = pointer.Any(uintptr(64)).(*uintptr)
Example
package main

import (
	"encoding/json"
	"fmt"
	"os"

	"github.com/xorcare/pointer"
)

func main() {
	type example struct {
		Bool      bool
		BoolPtr   *bool
		Uint      uint
		UintPtr   *uint
		String    string
		StringPtr *string
	}
	encoder := json.NewEncoder(os.Stdout)

	fmt.Print("Example use universal function: ")
	_ = encoder.Encode(example{
		Bool:      true,
		BoolPtr:   pointer.Any(true).(*bool),
		Uint:      32,
		UintPtr:   pointer.Any(uint(64)).(*uint),
		String:    "xor",
		StringPtr: pointer.Any("care").(*string),
	})

	fmt.Print("Example use specific functions: ")
	_ = encoder.Encode(example{
		Bool:      true,
		BoolPtr:   pointer.Bool(true),
		Uint:      32,
		UintPtr:   pointer.Uint(64),
		String:    "xor",
		StringPtr: pointer.String("care"),
	})

	fmt.Print("Example of using a non-standard hack: ")
	_ = encoder.Encode(example{
		Bool:      true,
		BoolPtr:   &[]bool{true}[0],
		Uint:      32,
		UintPtr:   &[]uint{64}[0],
		String:    "xor",
		StringPtr: &[]string{"care"}[0],
	})

}
Output:

Example use universal function: {"Bool":true,"BoolPtr":true,"Uint":32,"UintPtr":64,"String":"xor","StringPtr":"care"}
Example use specific functions: {"Bool":true,"BoolPtr":true,"Uint":32,"UintPtr":64,"String":"xor","StringPtr":"care"}
Example of using a non-standard hack: {"Bool":true,"BoolPtr":true,"Uint":32,"UintPtr":64,"String":"xor","StringPtr":"care"}

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *bool }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Bool(true)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]bool{true}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *bool <nil>
The value set by the library: *bool true
The value set in elegant way: *bool true

func Byte

func Byte(v byte) *byte

Byte is a helper routine that allocates a new byte value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *byte }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Byte(127)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]byte{255}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *uint8 <nil>
The value set by the library: *uint8 127
The value set in elegant way: *uint8 255

func Complex128

func Complex128(v complex128) *complex128

Complex128 is a helper routine that allocates a new complex128 value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *complex128 }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Complex128(complex128(55.753184))
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]complex128{complex128(48.743702)}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *complex128 <nil>
The value set by the library: *complex128 (55.753184+0i)
The value set in elegant way: *complex128 (48.743702+0i)

func Complex64

func Complex64(v complex64) *complex64

Complex64 is a helper routine that allocates a new complex64 value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *complex64 }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Complex64(complex64(55.751878))
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]complex64{complex64(48.752467)}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *complex64 <nil>
The value set by the library: *complex64 (55.751877+0i)
The value set in elegant way: *complex64 (48.75247+0i)

func Duration added in v1.1.0

func Duration(v time.Duration) *time.Duration

Duration is a helper routine that allocates a new time.Duration value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"
	"time"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *time.Duration }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Duration(time.Hour)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]time.Duration{time.Minute}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *time.Duration <nil>
The value set by the library: *time.Duration 1h0m0s
The value set in elegant way: *time.Duration 1m0s

func Float32

func Float32(v float32) *float32

Float32 is a helper routine that allocates a new float32 value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *float32 }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Float32(float32(55.753184))
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]float32{float32(48.743702)}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *float32 <nil>
The value set by the library: *float32 55.753185
The value set in elegant way: *float32 48.743702

func Float64

func Float64(v float64) *float64

Float64 is a helper routine that allocates a new float64 value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *float64 }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Float64(float64(55.753184))
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]float64{float64(48.743702)}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *float64 <nil>
The value set by the library: *float64 55.753184
The value set in elegant way: *float64 48.743702

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *int }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Int(1)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]int{2}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *int <nil>
The value set by the library: *int 1
The value set in elegant way: *int 2

func Int16

func Int16(v int16) *int16

Int16 is a helper routine that allocates a new int16 value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *int16 }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Int16(16383)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]int16{32767}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *int16 <nil>
The value set by the library: *int16 16383
The value set in elegant way: *int16 32767

func Int32

func Int32(v int32) *int32

Int32 is a helper routine that allocates a new int32 value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *int32 }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Int32(1073741823)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]int32{2147483647}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *int32 <nil>
The value set by the library: *int32 1073741823
The value set in elegant way: *int32 2147483647

func Int64

func Int64(v int64) *int64

Int64 is a helper routine that allocates a new int64 value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *int64 }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Int64(4611686018427387903)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]int64{9223372036854775807}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *int64 <nil>
The value set by the library: *int64 4611686018427387903
The value set in elegant way: *int64 9223372036854775807

func Int8

func Int8(v int8) *int8

Int8 is a helper routine that allocates a new int8 value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *int8 }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Int8(63)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]int8{127}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *int8 <nil>
The value set by the library: *int8 63
The value set in elegant way: *int8 127

func Of added in v1.2.0

func Of[Value any](v Value) *Value

Of is a helper routine that allocates a new any value to store v and returns a pointer to it.

Example
package main

import (
	"github.com/xorcare/pointer"
)

func main() {
	// Examples for values that have default type casting.
	var _ *int = pointer.Of(0)
	var _ *bool = pointer.Of(true)
	var _ *string = pointer.Of("example")

	// Example of usage with non default type casting.
	var _ *int8 = pointer.Of(int8(0))
	var _ *int8 = pointer.Of[int8](0)
}
Output:

func Rune

func Rune(v rune) *rune

Rune is a helper routine that allocates a new rune value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *rune }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Rune(120)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %3[2]d %[2]q", s.Pointer, *s.Pointer))

	s.Pointer = &[]rune{99}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %3[2]d %[2]q", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *int32 <nil>
The value set by the library: *int32 120 'x'
The value set in elegant way: *int32  99 'c'

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *string }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.String("xor")
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]string{"care"}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *string <nil>
The value set by the library: *string xor
The value set in elegant way: *string care

func Time added in v1.1.0

func Time(v time.Time) *time.Time

Time is a helper routine that allocates a new time.Time value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"
	"time"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *time.Time }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Time(time.Time{}.Add(time.Minute))
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]time.Time{time.Time{}.Add(time.Hour)}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *time.Time <nil>
The value set by the library: *time.Time 0001-01-01 00:01:00 +0000 UTC
The value set in elegant way: *time.Time 0001-01-01 01:00:00 +0000 UTC

func Uint

func Uint(v uint) *uint

Uint is a helper routine that allocates a new uint value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *uint }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Uint(1)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]uint{2}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *uint <nil>
The value set by the library: *uint 1
The value set in elegant way: *uint 2

func Uint16

func Uint16(v uint16) *uint16

Uint16 is a helper routine that allocates a new uint16 value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *uint16 }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Uint16(16383)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]uint16{32767}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *uint16 <nil>
The value set by the library: *uint16 16383
The value set in elegant way: *uint16 32767

func Uint32

func Uint32(v uint32) *uint32

Uint32 is a helper routine that allocates a new uint32 value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *uint32 }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Uint32(1073741823)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]uint32{2147483647}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *uint32 <nil>
The value set by the library: *uint32 1073741823
The value set in elegant way: *uint32 2147483647

func Uint64

func Uint64(v uint64) *uint64

Uint64 is a helper routine that allocates a new uint64 value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *uint64 }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Uint64(4611686018427387903)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]uint64{9223372036854775807}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *uint64 <nil>
The value set by the library: *uint64 4611686018427387903
The value set in elegant way: *uint64 9223372036854775807

func Uint8

func Uint8(v uint8) *uint8

Uint8 is a helper routine that allocates a new uint8 value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *uint8 }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Uint8(63)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]uint8{127}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *uint8 <nil>
The value set by the library: *uint8 63
The value set in elegant way: *uint8 127

func Uintptr

func Uintptr(v uintptr) *uintptr

Uintptr is a helper routine that allocates a new uintptr value to store v and returns a pointer to it.

Example
package main

import (
	"fmt"

	"github.com/xorcare/pointer"
)

func main() {
	s := struct{ Pointer *uintptr }{}
	fmt.Println(fmt.Sprintf("Zero pointer value: %T %v", s.Pointer, s.Pointer))

	s.Pointer = pointer.Uintptr(4611686018427387903)
	fmt.Println(fmt.Sprintf("The value set by the library: %T %v", s.Pointer, *s.Pointer))

	s.Pointer = &[]uintptr{9223372036854775807}[0]
	fmt.Println(fmt.Sprintf("The value set in elegant way: %T %v", s.Pointer, *s.Pointer))

}
Output:

Zero pointer value: *uintptr <nil>
The value set by the library: *uintptr 4611686018427387903
The value set in elegant way: *uintptr 9223372036854775807

Types

This section is empty.

Jump to

Keyboard shortcuts

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