ptr

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2023 License: MIT Imports: 1 Imported by: 28

README

ptr

The ptr package gives you some basic helpers for working with pointers in Go. The package is simply intended to make it easy to create pointers to things. E.g. instead of writing:

s := "some string"
b := &s

You'd just write

b := ptr.String("some string")

Usage

ptr.Bool(true)        // Returns *bool
ptr.Byte(byte('a'))   // Returns *byte
ptr.Float32(123.3)    // Returns *float32
ptr.Float64(123.3)    // Returns *float64
ptr.Int(123)          // Returns *int
ptr.Int8(123)         // Returns *int8
ptr.Int16(123)        // Returns *int16
ptr.Int32(123)        // Returns *int32
ptr.Int64(123)        // Returns *int64
ptr.Rune(123)         // Returns *rune
ptr.String("string")  // Returns *string
ptr.Time(time.Now())  // Returns *time.Time
ptr.Uint(123)         // Returns *uint
ptr.Uint8(123)        // Returns *uint8
ptr.Uint16(123)       // Returns *uint16
ptr.Uint32(123)       // Returns *uint32
ptr.Uint64(123)       // Returns *uint64

Running the tests

go test -v ./...

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(b bool) *bool

Bool returns a pointer to a boolean.

func Byte

func Byte(b byte) *byte

Byte returns a pointer to a byte.

func Float32

func Float32(f float32) *float32

Float32 returns a pointer to a float.

func Float64

func Float64(f float64) *float64

Float64 returns a pointer to a float.

func Int

func Int(i int) *int

Int returns a pointer to an int.

func Int16

func Int16(i int16) *int16

Int16 returns a pointer to an int.

func Int32

func Int32(i int32) *int32

Int32 returns a pointer to an int.

func Int64

func Int64(i int64) *int64

Int64 returns a pointer to an int.

func Int8

func Int8(i int8) *int8

Int8 returns a pointer to an int.

func Rune

func Rune(r rune) *rune

Rune returns a pointer to a rune.

func String

func String(s string) *string

String returns a pointer to a string.

func Time

func Time(t time.Time) *time.Time

Time returns a pointer to a time.Time object.

func Uint

func Uint(i uint) *uint

Uint returns a pointer to an uint.

func Uint16

func Uint16(i uint16) *uint16

Uint16 returns a pointer to an uint.

func Uint32

func Uint32(i uint32) *uint32

Uint32 returns a pointer to an uint.

func Uint64

func Uint64(i uint64) *uint64

Uint64 returns a pointer to an uint.

func Uint8

func Uint8(i uint8) *uint8

Uint8 returns a pointer to an uint.

Types

This section is empty.

Jump to

Keyboard shortcuts

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