pax_global_header00006660000000000000000000000064135416636030014521gustar00rootroot0000000000000052 comment=4f2b1f4deff73a28288291183baa1e9dff4a93a5 pointer-1.1.0/000077500000000000000000000000001354166360300132005ustar00rootroot00000000000000pointer-1.1.0/.travis.yml000066400000000000000000000001051354166360300153050ustar00rootroot00000000000000language: go sudo: false go: - 1.x - master script: go test -v pointer-1.1.0/LICENSE000066400000000000000000000020761354166360300142120ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015 Alexey Palazhchenko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pointer-1.1.0/README.md000066400000000000000000000023071354166360300144610ustar00rootroot00000000000000# pointer [![GoDoc](https://godoc.org/github.com/AlekSi/pointer?status.svg)](https://godoc.org/github.com/AlekSi/pointer) [![Build Status](https://travis-ci.org/AlekSi/pointer.svg)](https://travis-ci.org/AlekSi/pointer) Go package pointer provides helpers to get pointers to values of built-in types. ``` go get github.com/AlekSi/pointer ``` API is stable. [Documentation](http://godoc.org/github.com/AlekSi/pointer). ```go package motivationalexample import ( "encoding/json" "github.com/AlekSi/pointer" ) const ( defaultName = "some name" ) // Stuff contains optional fields. type Stuff struct { Name *string Comment *string Value *int64 Time *time.Time } // SomeStuff makes some JSON-encoded stuff. func SomeStuff() (data []byte, err error) { return json.Marshal(&Stuff{ Name: pointer.ToString(defaultName), // can't say &defaultName Comment: pointer.ToString("not yet"), // can't say &"not yet" Value: pointer.ToInt64(42), // can't say &42 or &int64(42) Time: pointer.ToTime(time.Date(2014, 6, 25, 12, 24, 40, 0, time.UTC)), // can't say &time.Date(…) }) } ``` pointer-1.1.0/go.mod000066400000000000000000000000521354166360300143030ustar00rootroot00000000000000module github.com/AlekSi/pointer go 1.11 pointer-1.1.0/pointer.go000066400000000000000000000051461354166360300152150ustar00rootroot00000000000000// Package pointer provides helpers to get pointers to values of built-in types. package pointer // import "github.com/AlekSi/pointer" import ( "time" ) /* Order as in spec: bool byte complex64 complex128 error float32 float64 int int8 int16 int32 int64 rune string uint uint8 uint16 uint32 uint64 uintptr time.Duration time.Time */ // ToBool returns a pointer to the passed bool value. func ToBool(b bool) *bool { return &b } // ToByte returns a pointer to the passed byte value. func ToByte(b byte) *byte { return &b } // ToComplex64 returns a pointer to the passed complex64 value. func ToComplex64(c complex64) *complex64 { return &c } // ToComplex128 returns a pointer to the passed complex128 value. func ToComplex128(c complex128) *complex128 { return &c } // ToError returns a pointer to the passed error value. func ToError(e error) *error { return &e } // ToFloat32 returns a pointer to the passed float32 value. func ToFloat32(f float32) *float32 { return &f } // ToFloat64 returns a pointer to the passed float64 value. func ToFloat64(f float64) *float64 { return &f } // ToInt returns a pointer to the passed int value. func ToInt(i int) *int { return &i } // ToInt8 returns a pointer to the passed int8 value. func ToInt8(i int8) *int8 { return &i } // ToInt16 returns a pointer to the passed int16 value. func ToInt16(i int16) *int16 { return &i } // ToInt32 returns a pointer to the passed int32 value. func ToInt32(i int32) *int32 { return &i } // ToInt64 returns a pointer to the passed int64 value. func ToInt64(i int64) *int64 { return &i } // ToRune returns a pointer to the passed rune value. func ToRune(r rune) *rune { return &r } // ToString returns a pointer to the passed string value. func ToString(s string) *string { return &s } // ToUint returns a pointer to the passed uint value. func ToUint(u uint) *uint { return &u } // ToUint8 returns a pointer to the passed uint8 value. func ToUint8(u uint8) *uint8 { return &u } // ToUint16 returns a pointer to the passed uint16 value. func ToUint16(u uint16) *uint16 { return &u } // ToUint32 returns a pointer to the passed uint32 value. func ToUint32(u uint32) *uint32 { return &u } // ToUint64 returns a pointer to the passed uint64 value. func ToUint64(u uint64) *uint64 { return &u } // ToUintptr returns a pointer to the passed uintptr value. func ToUintptr(u uintptr) *uintptr { return &u } // ToDuration returns a pointer to the passed time.Duration value. func ToDuration(d time.Duration) *time.Duration { return &d } // ToTime returns a pointer to the passed time.Time value. func ToTime(t time.Time) *time.Time { return &t } pointer-1.1.0/pointer_or_nil.go000066400000000000000000000103641354166360300165550ustar00rootroot00000000000000package pointer import ( "time" ) /* Order as in spec: bool byte complex64 complex128 error float32 float64 int int8 int16 int32 int64 rune string uint uint8 uint16 uint32 uint64 uintptr time.Duration time.Time */ // ToBoolOrNil returns a pointer to the passed bool value, or nil, if passed value is a zero value. func ToBoolOrNil(b bool) *bool { if b == false { return nil } return &b } // ToByteOrNil returns a pointer to the passed byte value, or nil, if passed value is a zero value. func ToByteOrNil(b byte) *byte { if b == 0 { return nil } return &b } // ToComplex64OrNil returns a pointer to the passed complex64 value, or nil, if passed value is a zero value. func ToComplex64OrNil(c complex64) *complex64 { if c == 0 { return nil } return &c } // ToComplex128OrNil returns a pointer to the passed complex128 value, or nil, if passed value is a zero value. func ToComplex128OrNil(c complex128) *complex128 { if c == 0 { return nil } return &c } // ToErrorOrNil returns a pointer to the passed error value, or nil, if passed value is a zero value. func ToErrorOrNil(e error) *error { if e == nil { return nil } return &e } // ToFloat32OrNil returns a pointer to the passed float32 value, or nil, if passed value is a zero value. func ToFloat32OrNil(f float32) *float32 { if f == 0 { return nil } return &f } // ToFloat64OrNil returns a pointer to the passed float64 value, or nil, if passed value is a zero value. func ToFloat64OrNil(f float64) *float64 { if f == 0 { return nil } return &f } // ToIntOrNil returns a pointer to the passed int value, or nil, if passed value is a zero value. func ToIntOrNil(i int) *int { if i == 0 { return nil } return &i } // ToInt8OrNil returns a pointer to the passed int8 value, or nil, if passed value is a zero value. func ToInt8OrNil(i int8) *int8 { if i == 0 { return nil } return &i } // ToInt16OrNil returns a pointer to the passed int16 value, or nil, if passed value is a zero value. func ToInt16OrNil(i int16) *int16 { if i == 0 { return nil } return &i } // ToInt32OrNil returns a pointer to the passed int32 value, or nil, if passed value is a zero value. func ToInt32OrNil(i int32) *int32 { if i == 0 { return nil } return &i } // ToInt64OrNil returns a pointer to the passed int64 value, or nil, if passed value is a zero value. func ToInt64OrNil(i int64) *int64 { if i == 0 { return nil } return &i } // ToRuneOrNil returns a pointer to the passed rune value, or nil, if passed value is a zero value. func ToRuneOrNil(r rune) *rune { if r == 0 { return nil } return &r } // ToStringOrNil returns a pointer to the passed string value, or nil, if passed value is a zero value. func ToStringOrNil(s string) *string { if s == "" { return nil } return &s } // ToUintOrNil returns a pointer to the passed uint value, or nil, if passed value is a zero value. func ToUintOrNil(u uint) *uint { if u == 0 { return nil } return &u } // ToUint8OrNil returns a pointer to the passed uint8 value, or nil, if passed value is a zero value. func ToUint8OrNil(u uint8) *uint8 { if u == 0 { return nil } return &u } // ToUint16OrNil returns a pointer to the passed uint16 value, or nil, if passed value is a zero value. func ToUint16OrNil(u uint16) *uint16 { if u == 0 { return nil } return &u } // ToUint32OrNil returns a pointer to the passed uint32 value, or nil, if passed value is a zero value. func ToUint32OrNil(u uint32) *uint32 { if u == 0 { return nil } return &u } // ToUint64OrNil returns a pointer to the passed uint64 value, or nil, if passed value is a zero value. func ToUint64OrNil(u uint64) *uint64 { if u == 0 { return nil } return &u } // ToUintptrOrNil returns a pointer to the passed uintptr value, or nil, if passed value is a zero value. func ToUintptrOrNil(u uintptr) *uintptr { if u == 0 { return nil } return &u } // ToDurationOrNil returns a pointer to the passed time.Duration value, or nil, if passed value is a zero value. func ToDurationOrNil(d time.Duration) *time.Duration { if d == 0 { return nil } return &d } // ToTimeOrNil returns a pointer to the passed time.Time value, or nil, if passed value is a zero value (t.IsZero() returns true). func ToTimeOrNil(t time.Time) *time.Time { if t.IsZero() { return nil } return &t } pointer-1.1.0/pointer_test.go000066400000000000000000000243501354166360300162520ustar00rootroot00000000000000package pointer import ( "encoding/json" "errors" "fmt" "testing" "time" ) /* Order as in spec: bool byte complex64 complex128 error float32 float64 int int8 int16 int32 int64 rune string uint uint8 uint16 uint32 uint64 uintptr time.Duration time.Time */ func TestBool(t *testing.T) { var x bool if *ToBool(x) != x { t.Errorf("*ToBool(%v)", x) } if ToBoolOrNil(x) != nil { t.Errorf("ToBoolOrNil(%v)", x) } if GetBool(nil) != x { t.Errorf("GetBool(%v)", nil) } x = true if *ToBool(x) != x { t.Errorf("*ToBool(%v)", x) } if *ToBoolOrNil(x) != x { t.Errorf("*ToBoolOrNil(%v)", x) } if GetBool(&x) != x { t.Errorf("GetBool(%v)", &x) } } func TestByte(t *testing.T) { var x byte if *ToByte(x) != x { t.Errorf("*ToByte(%v)", x) } if ToByteOrNil(x) != nil { t.Errorf("ToByteOrNil(%v)", x) } if GetByte(nil) != x { t.Errorf("GetByte(%v)", nil) } x = 42 if *ToByte(x) != x { t.Errorf("*ToByte(%v)", x) } if *ToByteOrNil(x) != x { t.Errorf("*ToByteOrNil(%v)", x) } if GetByte(&x) != x { t.Errorf("GetByte(%v)", &x) } } func TestComplex64(t *testing.T) { var x complex64 if *ToComplex64(x) != x { t.Errorf("*ToComplex64(%v)", x) } if ToComplex64OrNil(x) != nil { t.Errorf("ToComplex64OrNil(%v)", x) } if GetComplex64(nil) != x { t.Errorf("GetComplex64(%v)", nil) } x = 42 if *ToComplex64(x) != x { t.Errorf("*ToComplex64(%v)", x) } if *ToComplex64OrNil(x) != x { t.Errorf("*ToComplex64OrNil(%v)", x) } if GetComplex64(&x) != x { t.Errorf("GetComplex64(%v)", &x) } } func TestComplex128(t *testing.T) { var x complex128 if *ToComplex128(x) != x { t.Errorf("*ToComplex128(%v)", x) } if ToComplex128OrNil(x) != nil { t.Errorf("ToComplex128OrNil(%v)", x) } if GetComplex128(nil) != x { t.Errorf("GetComplex128(%v)", nil) } x = 42 if *ToComplex128(x) != x { t.Errorf("*ToComplex128(%v)", x) } if *ToComplex128OrNil(x) != x { t.Errorf("*ToComplex128OrNil(%v)", x) } if GetComplex128(&x) != x { t.Errorf("GetComplex128(%v)", &x) } } func TestError(t *testing.T) { var x error if *ToError(x) != x { t.Errorf("*ToError(%v)", x) } if ToErrorOrNil(x) != nil { t.Errorf("ToErrorOrNil(%v)", x) } if GetError(nil) != x { t.Errorf("GetError(%v)", nil) } x = errors.New("error") if *ToError(x) != x { t.Errorf("*ToError(%v)", x) } if *ToErrorOrNil(x) != x { t.Errorf("*ToErrorOrNil(%v)", x) } if GetError(&x) != x { t.Errorf("GetError(%v)", &x) } } func TestFloat32(t *testing.T) { var x float32 if *ToFloat32(x) != x { t.Errorf("*ToFloat32(%v)", x) } if ToFloat32OrNil(x) != nil { t.Errorf("ToFloat32OrNil(%v)", x) } if GetFloat32(nil) != x { t.Errorf("GetFloat32(%v)", nil) } x = 42 if *ToFloat32(x) != x { t.Errorf("*ToFloat32(%v)", x) } if *ToFloat32OrNil(x) != x { t.Errorf("*ToFloat32OrNil(%v)", x) } if GetFloat32(&x) != x { t.Errorf("GetFloat32(%v)", &x) } } func TestFloat64(t *testing.T) { var x float64 if *ToFloat64(x) != x { t.Errorf("*ToFloat64(%v)", x) } if ToFloat64OrNil(x) != nil { t.Errorf("ToFloat64OrNil(%v)", x) } if GetFloat64(nil) != x { t.Errorf("GetFloat64(%v)", nil) } x = 42 if *ToFloat64(x) != x { t.Errorf("*ToFloat64(%v)", x) } if *ToFloat64OrNil(x) != x { t.Errorf("*ToFloat64OrNil(%v)", x) } if GetFloat64(&x) != x { t.Errorf("GetFloat64(%v)", &x) } } func TestInt(t *testing.T) { var x int if *ToInt(x) != x { t.Errorf("*ToInt(%v)", x) } if ToIntOrNil(x) != nil { t.Errorf("ToIntOrNil(%v)", x) } if GetInt(nil) != x { t.Errorf("GetInt(%v)", nil) } x = 42 if *ToInt(x) != x { t.Errorf("*ToInt(%v)", x) } if *ToIntOrNil(x) != x { t.Errorf("*ToIntOrNil(%v)", x) } if GetInt(&x) != x { t.Errorf("GetInt(%v)", &x) } } func TestInt8(t *testing.T) { var x int8 if *ToInt8(x) != x { t.Errorf("*ToInt8(%v)", x) } if ToInt8OrNil(x) != nil { t.Errorf("ToInt8OrNil(%v)", x) } if GetInt8(nil) != x { t.Errorf("GetInt8(%v)", nil) } x = 42 if *ToInt8(x) != x { t.Errorf("*ToInt8(%v)", x) } if *ToInt8OrNil(x) != x { t.Errorf("*ToInt8OrNil(%v)", x) } if GetInt8(&x) != x { t.Errorf("GetInt8(%v)", &x) } } func TestInt16(t *testing.T) { var x int16 if *ToInt16(x) != x { t.Errorf("*ToInt16(%v)", x) } if ToInt16OrNil(x) != nil { t.Errorf("ToInt16OrNil(%v)", x) } if GetInt16(nil) != x { t.Errorf("GetInt16(%v)", nil) } x = 42 if *ToInt16(x) != x { t.Errorf("*ToInt16(%v)", x) } if *ToInt16OrNil(x) != x { t.Errorf("*ToInt16OrNil(%v)", x) } if GetInt16(&x) != x { t.Errorf("GetInt16(%v)", &x) } } func TestInt32(t *testing.T) { var x int32 if *ToInt32(x) != x { t.Errorf("*ToInt32(%v)", x) } if ToInt32OrNil(x) != nil { t.Errorf("ToInt32OrNil(%v)", x) } if GetInt32(nil) != x { t.Errorf("GetInt32(%v)", nil) } x = 42 if *ToInt32(x) != x { t.Errorf("*ToInt32(%v)", x) } if *ToInt32OrNil(x) != x { t.Errorf("*ToInt32OrNil(%v)", x) } if GetInt32(&x) != x { t.Errorf("GetInt32(%v)", &x) } } func TestInt64(t *testing.T) { var x int64 if *ToInt64(x) != x { t.Errorf("*ToInt64(%v)", x) } if ToInt64OrNil(x) != nil { t.Errorf("ToInt64OrNil(%v)", x) } if GetInt64(nil) != x { t.Errorf("GetInt64(%v)", nil) } x = 42 if *ToInt64(x) != x { t.Errorf("*ToInt64(%v)", x) } if *ToInt64OrNil(x) != x { t.Errorf("*ToInt64OrNil(%v)", x) } if GetInt64(&x) != x { t.Errorf("GetInt64(%v)", &x) } } func TestRune(t *testing.T) { var x rune if *ToRune(x) != x { t.Errorf("*ToRune(%v)", x) } if ToRuneOrNil(x) != nil { t.Errorf("ToRuneOrNil(%v)", x) } if GetRune(nil) != x { t.Errorf("GetRune(%v)", nil) } x = 'x' if *ToRune(x) != x { t.Errorf("*ToRune(%v)", x) } if *ToRuneOrNil(x) != x { t.Errorf("*ToRuneOrNil(%v)", x) } if GetRune(&x) != x { t.Errorf("GetRune(%v)", &x) } } func TestString(t *testing.T) { var x string if *ToString(x) != x { t.Errorf("*ToString(%v)", x) } if ToStringOrNil(x) != nil { t.Errorf("ToStringOrNil(%v)", x) } if GetString(nil) != x { t.Errorf("GetString(%v)", nil) } x = "x" if *ToString(x) != x { t.Errorf("*ToString(%v)", x) } if *ToStringOrNil(x) != x { t.Errorf("*ToStringOrNil(%v)", x) } if GetString(&x) != x { t.Errorf("GetString(%v)", &x) } } func TestUint(t *testing.T) { var x uint if *ToUint(x) != x { t.Errorf("*ToUint(%v)", x) } if ToUintOrNil(x) != nil { t.Errorf("ToUintOrNil(%v)", x) } if GetUint(nil) != x { t.Errorf("GetUint(%v)", nil) } x = 42 if *ToUint(x) != x { t.Errorf("*ToUint(%v)", x) } if *ToUintOrNil(x) != x { t.Errorf("*ToUintOrNil(%v)", x) } if GetUint(&x) != x { t.Errorf("GetUint(%v)", &x) } } func TestUint8(t *testing.T) { var x uint8 if *ToUint8(x) != x { t.Errorf("*ToUint8(%v)", x) } if ToUint8OrNil(x) != nil { t.Errorf("ToUint8OrNil(%v)", x) } if GetUint8(nil) != x { t.Errorf("GetUint8(%v)", nil) } x = 42 if *ToUint8(x) != x { t.Errorf("*ToUint8(%v)", x) } if *ToUint8OrNil(x) != x { t.Errorf("*ToUint8OrNil(%v)", x) } if GetUint8(&x) != x { t.Errorf("GetUint8(%v)", &x) } } func TestUint16(t *testing.T) { var x uint16 if *ToUint16(x) != x { t.Errorf("*ToUint16(%v)", x) } if ToUint16OrNil(x) != nil { t.Errorf("ToUint16OrNil(%v)", x) } if GetUint16(nil) != x { t.Errorf("GetUint16(%v)", nil) } x = 42 if *ToUint16(x) != x { t.Errorf("*ToUint16(%v)", x) } if *ToUint16OrNil(x) != x { t.Errorf("*ToUint16OrNil(%v)", x) } if GetUint16(&x) != x { t.Errorf("GetUint16(%v)", &x) } } func TestUint32(t *testing.T) { var x uint32 if *ToUint32(x) != x { t.Errorf("*ToUint32(%v)", x) } if ToUint32OrNil(x) != nil { t.Errorf("ToUint32OrNil(%v)", x) } if GetUint32(nil) != x { t.Errorf("GetUint32(%v)", nil) } x = 42 if *ToUint32(x) != x { t.Errorf("*ToUint32(%v)", x) } if *ToUint32OrNil(x) != x { t.Errorf("*ToUint32OrNil(%v)", x) } if GetUint32(&x) != x { t.Errorf("GetUint32(%v)", &x) } } func TestUint64(t *testing.T) { var x uint64 if *ToUint64(x) != x { t.Errorf("*ToUint64(%v)", x) } if ToUint64OrNil(x) != nil { t.Errorf("ToUint64OrNil(%v)", x) } if GetUint64(nil) != x { t.Errorf("GetUint64(%v)", nil) } x = 42 if *ToUint64(x) != x { t.Errorf("*ToUint64(%v)", x) } if *ToUint64OrNil(x) != x { t.Errorf("*ToUint64OrNil(%v)", x) } if GetUint64(&x) != x { t.Errorf("GetUint64(%v)", &x) } } func TestUintptr(t *testing.T) { var x uintptr if *ToUintptr(x) != x { t.Errorf("*ToUintptr(%v)", x) } if ToUintptrOrNil(x) != nil { t.Errorf("ToUintptrOrNil(%v)", x) } if GetUintptr(nil) != x { t.Errorf("GetUintptr(%v)", nil) } x = 42 if *ToUintptr(x) != x { t.Errorf("*ToUintptr(%v)", x) } if *ToUintptrOrNil(x) != x { t.Errorf("*ToUintptrOrNil(%v)", x) } if GetUintptr(&x) != x { t.Errorf("GetUintptr(%v)", &x) } } func TestDuration(t *testing.T) { var x time.Duration if *ToDuration(x) != x { t.Errorf("*ToDuration(%v)", x) } if ToDurationOrNil(x) != nil { t.Errorf("ToDurationOrNil(%v)", x) } if GetDuration(nil) != x { t.Errorf("GetDuration(%v)", nil) } x = time.Second if *ToDuration(x) != x { t.Errorf("*ToDuration(%v)", x) } if *ToDurationOrNil(x) != x { t.Errorf("*ToDurationOrNil(%v)", x) } if GetDuration(&x) != x { t.Errorf("GetDuration(%v)", &x) } } func TestTime(t *testing.T) { var x time.Time if *ToTime(x) != x { t.Errorf("*ToTime(%v)", x) } if ToTimeOrNil(x) != nil { t.Errorf("ToTimeOrNil(%v)", x) } if GetTime(nil) != x { t.Errorf("GetTime(%v)", nil) } x = time.Date(2014, 6, 25, 12, 24, 40, 0, time.UTC) if *ToTime(x) != x { t.Errorf("*ToTime(%v)", x) } if *ToTimeOrNil(x) != x { t.Errorf("*ToTimeOrNil(%v)", x) } if GetTime(&x) != x { t.Errorf("GetTime(%v)", &x) } } func Example() { const ( defaultName = "some name" ) // Stuff contains optional fields. type Stuff struct { Name *string Comment *string Value *int64 Time *time.Time } b, _ := json.Marshal(&Stuff{ Name: ToString(defaultName), // can't say &defaultName Comment: ToString("not yet"), // can't say &"not yet" Value: ToInt64(42), // can't say &42 or &int64(42) Time: ToTime(time.Date(2014, 6, 25, 12, 24, 40, 0, time.UTC)), // can't say &time.Date(…) }) fmt.Printf("%s", b) // Output: {"Name":"some name","Comment":"not yet","Value":42,"Time":"2014-06-25T12:24:40Z"} } pointer-1.1.0/value.go000066400000000000000000000075761354166360300146620ustar00rootroot00000000000000package pointer import ( "time" ) /* Order as in spec: bool byte complex64 complex128 error float32 float64 int int8 int16 int32 int64 rune string uint uint8 uint16 uint32 uint64 uintptr time.Duration time.Time */ // GetBool returns the value of the bool pointer passed in or false if the pointer is nil. func GetBool(b *bool) bool { if b == nil { return false } return *b } // GetByte returns the value of the byte pointer passed in or 0 if the pointer is nil. func GetByte(b *byte) byte { if b == nil { return 0 } return *b } // GetComplex64 returns the value of the complex64 pointer passed in or 0 if the pointer is nil. func GetComplex64(c *complex64) complex64 { if c == nil { return 0 } return *c } // GetComplex128 returns the value of the complex128 pointer passed in or 0 if the pointer is nil. func GetComplex128(c *complex128) complex128 { if c == nil { return 0 } return *c } // GetError returns the value of the error pointer passed in or nil if the pointer is nil. func GetError(e *error) error { if e == nil { return nil } return *e } // GetFloat32 returns the value of the float32 pointer passed in or 0 if the pointer is nil. func GetFloat32(f *float32) float32 { if f == nil { return 0 } return *f } // GetFloat64 returns the value of the float64 pointer passed in or 0 if the pointer is nil. func GetFloat64(f *float64) float64 { if f == nil { return 0 } return *f } // GetInt returns the value of the int pointer passed in or 0 if the pointer is nil. func GetInt(i *int) int { if i == nil { return 0 } return *i } // GetInt8 returns the value of the int8 pointer passed in or 0 if the pointer is nil. func GetInt8(i *int8) int8 { if i == nil { return 0 } return *i } // GetInt16 returns the value of the int16 pointer passed in or 0 if the pointer is nil. func GetInt16(i *int16) int16 { if i == nil { return 0 } return *i } // GetInt32 returns the value of the int32 pointer passed in or 0 if the pointer is nil. func GetInt32(i *int32) int32 { if i == nil { return 0 } return *i } // GetInt64 returns the value of the int64 pointer passed in or 0 if the pointer is nil. func GetInt64(i *int64) int64 { if i == nil { return 0 } return *i } // GetRune returns the value of the rune pointer passed in or 0 if the pointer is nil. func GetRune(r *rune) rune { if r == nil { return 0 } return *r } // GetString returns the value of the string pointer passed in or empty string if the pointer is nil. func GetString(s *string) string { if s == nil { return "" } return *s } // GetUint returns the value of the uint pointer passed in or 0 if the pointer is nil. func GetUint(u *uint) uint { if u == nil { return 0 } return *u } // GetUint8 returns the value of the uint8 pointer passed in or 0 if the pointer is nil. func GetUint8(u *uint8) uint8 { if u == nil { return 0 } return *u } // GetUint16 returns the value of the uint16 pointer passed in or 0 if the pointer is nil. func GetUint16(u *uint16) uint16 { if u == nil { return 0 } return *u } // GetUint32 returns the value of the uint32 pointer passed in or 0 if the pointer is nil. func GetUint32(u *uint32) uint32 { if u == nil { return 0 } return *u } // GetUint64 returns the value of the uint64 pointer passed in or 0 if the pointer is nil. func GetUint64(u *uint64) uint64 { if u == nil { return 0 } return *u } // GetUintptr returns the value of the uintptr pointer passed in or 0 if the pointer is nil. func GetUintptr(u *uintptr) uintptr { if u == nil { return 0 } return *u } // GetDuration returns the value of the duration pointer passed in or 0 if the pointer is nil. func GetDuration(d *time.Duration) time.Duration { if d == nil { return 0 } return *d } // GetTime returns the value of the time pointer passed in or zero time.Time if the pointer is nil. func GetTime(t *time.Time) time.Time { if t == nil { return time.Time{} } return *t }