Documentation
¶
Overview ¶
Package optional exports types that wrap the builtin types (int, bool, etc) to represent the lack of value. The types guarantee safety by requiring the developer to unwrap them to get to the inner value. This prevents a nil value being operated on. Optionals marshal to XML and JSON like their underlying type, and omitempty works just like their wrapped type would with a pointer, but without the use of pointers.
These types are an alternative to using pointers, zero values, or similar null wrapper packages. Unlike similar solutions these will omit correctly from XML and JSON without the use of pointers and the compiler will ensure their value is not used when empty.
The package also contains a template that you can use with go generate to create optional types for your own types. See below for instructions on how to use the template.
Examples ¶
Wrap a pointer in an optional:
var i *int = ... o := optional.OfIntPtr(i)
Unwrap it safely:
o.If(func(i int) { // called if o is not empty }) if _, ok := o.Get(); ok { // ok is true if o is not empty }
Or get it's value with a fallback to a default:
_ := o.ElseZero() // returns the zero value if empty _ := o.Else(100) // returns 100 if o is empty _ := o.ElseFunc(func() { // called if o is empty return 100 })
XML and JSON are supported out of the box. Use `omitempty` to omit the field when the optional is empty:
s := struct { Int1 optional.Int `json:"int1,omitempty"` Int2 optional.Int `json:"int2,omitempty"` Int3 optional.Int `json:"int3,omitempty"` }{ Int1: optional.EmptyInt(), Int2: optional.OfInt(1000), Int3: optional.OfIntPtr(nil), } output, _ := json.Marshal(s) // output = {"int2":1000}
Templates ¶
Use the Optional template for your own types by installing gotemplate.
go get github.com/ncw/gotemplate
Then add a `go generate` comment for your type to any `.go` file in your package.
//go:generate gotemplate "4d63.com/optional/template" OptionalMyType(MyType)
Examples ¶
See the examples for more approaches to use.
Example (Else) ¶
package main import ( "fmt" "4d63.com/optional" ) func main() { i := 1001 values := []optional.Int{ optional.EmptyInt(), optional.OfInt(1000), optional.OfIntPtr(nil), optional.OfIntPtr(&i), } for _, v := range values { fmt.Println(v.Else(1)) } }
Output: 1 1000 1 1001
Example (ElseFunc) ¶
package main import ( "fmt" "4d63.com/optional" ) func main() { i := 1001 values := []optional.Int{ optional.EmptyInt(), optional.OfInt(1000), optional.OfIntPtr(nil), optional.OfIntPtr(&i), } for _, v := range values { fmt.Println(v.ElseFunc(func() int { return 2 })) } }
Output: 2 1000 2 1001
Example (ElseZero) ¶
package main import ( "fmt" "4d63.com/optional" ) func main() { i := 1001 values := []optional.Int{ optional.EmptyInt(), optional.OfInt(1000), optional.OfIntPtr(nil), optional.OfIntPtr(&i), } for _, v := range values { fmt.Println(v.ElseZero()) } }
Output: 0 1000 0 1001
Example (Get) ¶
package main import ( "fmt" "4d63.com/optional" ) func main() { i := 1001 values := []optional.Int{ optional.EmptyInt(), optional.OfInt(1000), optional.OfIntPtr(nil), optional.OfIntPtr(&i), } for _, v := range values { if i, ok := v.Get(); ok { fmt.Println(i) } } }
Output: 1000 1001
Example (If) ¶
package main import ( "fmt" "4d63.com/optional" ) func main() { i := 1001 values := []optional.Int{ optional.EmptyInt(), optional.OfInt(1000), optional.OfIntPtr(nil), optional.OfIntPtr(&i), } for _, v := range values { v.If(func(i int) { fmt.Println(i) }) } }
Output: 1000 1001
Example (JsonMarshalEmpty) ¶
package main import ( "encoding/json" "fmt" "4d63.com/optional" ) func main() { s := struct { Bool optional.Bool `json:"bool"` Byte optional.Byte `json:"byte"` Float32 optional.Float32 `json:"float32"` Float64 optional.Float64 `json:"float64"` Int16 optional.Int16 `json:"int16"` Int32 optional.Int32 `json:"int32"` Int64 optional.Int64 `json:"int64"` Int optional.Int `json:"int"` Rune optional.Rune `json:"rune"` String optional.String `json:"string"` Time optional.Time `json:"time"` Uint16 optional.Uint16 `json:"uint16"` Uint32 optional.Uint32 `json:"uint32"` Uint64 optional.Uint64 `json:"uint64"` Uint optional.Uint `json:"uint"` Uintptr optional.Uintptr `json:"uintptr"` }{ Bool: optional.EmptyBool(), Byte: optional.EmptyByte(), Float32: optional.EmptyFloat32(), Float64: optional.EmptyFloat64(), Int16: optional.EmptyInt16(), Int32: optional.EmptyInt32(), Int64: optional.EmptyInt64(), Int: optional.EmptyInt(), Rune: optional.EmptyRune(), String: optional.EmptyString(), Time: optional.EmptyTime(), Uint16: optional.EmptyUint16(), Uint32: optional.EmptyUint32(), Uint64: optional.EmptyUint64(), Uint: optional.EmptyUint(), Uintptr: optional.EmptyUintptr(), } output, _ := json.MarshalIndent(s, "", " ") fmt.Println(string(output)) }
Output: { "bool": false, "byte": 0, "float32": 0, "float64": 0, "int16": 0, "int32": 0, "int64": 0, "int": 0, "rune": 0, "string": "", "time": "0001-01-01T00:00:00Z", "uint16": 0, "uint32": 0, "uint64": 0, "uint": 0, "uintptr": 0 }
Example (JsonMarshalOmitEmpty) ¶
package main import ( "encoding/json" "fmt" "4d63.com/optional" ) func main() { s := struct { Bool optional.Bool `json:"bool,omitempty"` Byte optional.Byte `json:"byte,omitempty"` Float32 optional.Float32 `json:"float32,omitempty"` Float64 optional.Float64 `json:"float64,omitempty"` Int16 optional.Int16 `json:"int16,omitempty"` Int32 optional.Int32 `json:"int32,omitempty"` Int64 optional.Int64 `json:"int64,omitempty"` Int optional.Int `json:"int,omitempty"` Rune optional.Rune `json:"rune,omitempty"` String optional.String `json:"string,omitempty"` Time optional.Time `json:"time,omitempty"` Uint16 optional.Uint16 `json:"uint16,omitempty"` Uint32 optional.Uint32 `json:"uint32,omitempty"` Uint64 optional.Uint64 `json:"uint64,omitempty"` Uint optional.Uint `json:"uint,omitempty"` Uintptr optional.Uintptr `json:"uintptr,omitempty"` }{ Bool: optional.EmptyBool(), Byte: optional.EmptyByte(), Float32: optional.EmptyFloat32(), Float64: optional.EmptyFloat64(), Int16: optional.EmptyInt16(), Int32: optional.EmptyInt32(), Int64: optional.EmptyInt64(), Int: optional.EmptyInt(), Rune: optional.EmptyRune(), String: optional.EmptyString(), Time: optional.EmptyTime(), Uint16: optional.EmptyUint16(), Uint32: optional.EmptyUint32(), Uint64: optional.EmptyUint64(), Uint: optional.EmptyUint(), Uintptr: optional.EmptyUintptr(), } output, _ := json.MarshalIndent(s, "", " ") fmt.Println(string(output)) }
Output: {}
Example (JsonMarshalPresent) ¶
package main import ( "encoding/json" "fmt" "time" "4d63.com/optional" ) func main() { s := struct { Bool optional.Bool `json:"bool"` Byte optional.Byte `json:"byte"` Float32 optional.Float32 `json:"float32"` Float64 optional.Float64 `json:"float64"` Int16 optional.Int16 `json:"int16"` Int32 optional.Int32 `json:"int32"` Int64 optional.Int64 `json:"int64"` Int optional.Int `json:"int"` Rune optional.Rune `json:"rune"` String optional.String `json:"string"` Time optional.Time `json:"time"` Uint16 optional.Uint16 `json:"uint16"` Uint32 optional.Uint32 `json:"uint32"` Uint64 optional.Uint64 `json:"uint64"` Uint optional.Uint `json:"uint"` Uintptr optional.Uintptr `json:"uintptr"` }{ Bool: optional.OfBool(true), Byte: optional.OfByte(1), Float32: optional.OfFloat32(2.1), Float64: optional.OfFloat64(2.2), Int16: optional.OfInt16(3), Int32: optional.OfInt32(4), Int64: optional.OfInt64(5), Int: optional.OfInt(6), Rune: optional.OfRune(7), String: optional.OfString("string"), Time: optional.OfTime(time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC)), Uint16: optional.OfUint16(8), Uint32: optional.OfUint32(9), Uint64: optional.OfUint64(10), Uint: optional.OfUint(11), Uintptr: optional.OfUintptr(12), } output, _ := json.MarshalIndent(s, "", " ") fmt.Println(string(output)) }
Output: { "bool": true, "byte": 1, "float32": 2.1, "float64": 2.2, "int16": 3, "int32": 4, "int64": 5, "int": 6, "rune": 7, "string": "string", "time": "2006-01-02T15:04:05Z", "uint16": 8, "uint32": 9, "uint64": 10, "uint": 11, "uintptr": 12 }
Example (JsonUnmarshalEmpty) ¶
package main import ( "encoding/json" "fmt" "4d63.com/optional" ) func main() { s := struct { Bool optional.Bool `json:"bool"` Byte optional.Byte `json:"byte"` Float32 optional.Float32 `json:"float32"` Float64 optional.Float64 `json:"float64"` Int16 optional.Int16 `json:"int16"` Int32 optional.Int32 `json:"int32"` Int64 optional.Int64 `json:"int64"` Int optional.Int `json:"int"` Rune optional.Rune `json:"rune"` String optional.String `json:"string"` Time optional.Time `json:"time"` Uint16 optional.Uint16 `json:"uint16"` Uint32 optional.Uint32 `json:"uint32"` Uint64 optional.Uint64 `json:"uint64"` Uint optional.Uint `json:"uint"` Uintptr optional.Uintptr `json:"uintptr"` }{} x := `{}` json.Unmarshal([]byte(x), &s) fmt.Println("Bool:", s.Bool.IsPresent()) fmt.Println("Byte:", s.Byte.IsPresent()) fmt.Println("Float32:", s.Float32.IsPresent()) fmt.Println("Float64:", s.Float64.IsPresent()) fmt.Println("Int16:", s.Int16.IsPresent()) fmt.Println("Int32:", s.Int32.IsPresent()) fmt.Println("Int64:", s.Int64.IsPresent()) fmt.Println("Int:", s.Int.IsPresent()) fmt.Println("Rune:", s.Rune.IsPresent()) fmt.Println("String:", s.String.IsPresent()) fmt.Println("Time:", s.Time.IsPresent()) fmt.Println("Uint16:", s.Uint16.IsPresent()) fmt.Println("Uint32:", s.Uint32.IsPresent()) fmt.Println("Uint64:", s.Uint64.IsPresent()) fmt.Println("Uint64:", s.Uint64.IsPresent()) fmt.Println("Uint:", s.Uint.IsPresent()) fmt.Println("Uintptr:", s.Uint.IsPresent()) }
Output: Bool: false Byte: false Float32: false Float64: false Int16: false Int32: false Int64: false Int: false Rune: false String: false Time: false Uint16: false Uint32: false Uint64: false Uint64: false Uint: false Uintptr: false
Example (JsonUnmarshalPresent) ¶
package main import ( "encoding/json" "fmt" "4d63.com/optional" ) func main() { s := struct { Bool optional.Bool `json:"bool"` Byte optional.Byte `json:"byte"` Float32 optional.Float32 `json:"float32"` Float64 optional.Float64 `json:"float64"` Int16 optional.Int16 `json:"int16"` Int32 optional.Int32 `json:"int32"` Int64 optional.Int64 `json:"int64"` Int optional.Int `json:"int"` Rune optional.Rune `json:"rune"` String optional.String `json:"string"` Time optional.Time `json:"time"` Uint16 optional.Uint16 `json:"uint16"` Uint32 optional.Uint32 `json:"uint32"` Uint64 optional.Uint64 `json:"uint64"` Uint optional.Uint `json:"uint"` Uintptr optional.Uintptr `json:"uintptr"` }{} x := `{ "bool": false, "byte": 0, "float32": 0, "float64": 0, "int16": 0, "int32": 0, "int64": 0, "int": 0, "rune": 0, "string": "string", "time": "0001-01-01T00:00:00Z", "uint16": 0, "uint32": 0, "uint64": 0, "uint": 0, "uintptr": 0 }` json.Unmarshal([]byte(x), &s) fmt.Println("Bool:", s.Bool.IsPresent(), s.Bool) fmt.Println("Byte:", s.Byte.IsPresent(), s.Byte) fmt.Println("Float32:", s.Float32.IsPresent(), s.Float32) fmt.Println("Float64:", s.Float64.IsPresent(), s.Float64) fmt.Println("Int16:", s.Int16.IsPresent(), s.Int16) fmt.Println("Int32:", s.Int32.IsPresent(), s.Int32) fmt.Println("Int64:", s.Int64.IsPresent(), s.Int64) fmt.Println("Int:", s.Int.IsPresent(), s.Int) fmt.Println("Rune:", s.Rune.IsPresent(), s.Rune) fmt.Println("String:", s.String.IsPresent(), s.String) fmt.Println("Time:", s.Time.IsPresent(), s.Time) fmt.Println("Uint16:", s.Uint16.IsPresent(), s.Uint16) fmt.Println("Uint32:", s.Uint32.IsPresent(), s.Uint32) fmt.Println("Uint64:", s.Uint64.IsPresent(), s.Uint64) fmt.Println("Uint64:", s.Uint64.IsPresent(), s.Uint64) fmt.Println("Uint:", s.Uint.IsPresent(), s.Uint) fmt.Println("Uintptr:", s.Uint.IsPresent(), s.Uint) }
Output: Bool: true false Byte: true 0 Float32: true 0 Float64: true 0 Int16: true 0 Int32: true 0 Int64: true 0 Int: true 0 Rune: true 0 String: true string Time: true 0001-01-01 00:00:00 +0000 UTC Uint16: true 0 Uint32: true 0 Uint64: true 0 Uint64: true 0 Uint: true 0 Uintptr: true 0
Example (XmlMarshalEmpty) ¶
package main import ( "encoding/xml" "fmt" "4d63.com/optional" ) func main() { s := struct { XMLName xml.Name `xml:"s"` Bool optional.Bool `xml:"bool"` Byte optional.Byte `xml:"byte"` Float32 optional.Float32 `xml:"float32"` Float64 optional.Float64 `xml:"float64"` Int16 optional.Int16 `xml:"int16"` Int32 optional.Int32 `xml:"int32"` Int64 optional.Int64 `xml:"int64"` Int optional.Int `xml:"int"` Rune optional.Rune `xml:"rune"` String optional.String `xml:"string"` Time optional.Time `xml:"time"` Uint16 optional.Uint16 `xml:"uint16"` Uint32 optional.Uint32 `xml:"uint32"` Uint64 optional.Uint64 `xml:"uint64"` Uint optional.Uint `xml:"uint"` Uintptr optional.Uintptr `xml:"uintptr"` }{ Bool: optional.EmptyBool(), Byte: optional.EmptyByte(), Float32: optional.EmptyFloat32(), Float64: optional.EmptyFloat64(), Int16: optional.EmptyInt16(), Int32: optional.EmptyInt32(), Int64: optional.EmptyInt64(), Int: optional.EmptyInt(), Rune: optional.EmptyRune(), String: optional.EmptyString(), Time: optional.EmptyTime(), Uint16: optional.EmptyUint16(), Uint32: optional.EmptyUint32(), Uint64: optional.EmptyUint64(), Uint: optional.EmptyUint(), Uintptr: optional.EmptyUintptr(), } output, _ := xml.MarshalIndent(s, "", " ") fmt.Println(string(output)) }
Output: <s> <bool>false</bool> <byte>0</byte> <float32>0</float32> <float64>0</float64> <int16>0</int16> <int32>0</int32> <int64>0</int64> <int>0</int> <rune>0</rune> <string></string> <time>0001-01-01T00:00:00Z</time> <uint16>0</uint16> <uint32>0</uint32> <uint64>0</uint64> <uint>0</uint> <uintptr>0</uintptr> </s>
Example (XmlMarshalOmitEmpty) ¶
package main import ( "encoding/xml" "fmt" "4d63.com/optional" ) func main() { s := struct { XMLName xml.Name `xml:"s"` Bool optional.Bool `xml:"bool,omitempty"` Byte optional.Byte `xml:"byte,omitempty"` Float32 optional.Float32 `xml:"float32,omitempty"` Float64 optional.Float64 `xml:"float64,omitempty"` Int16 optional.Int16 `xml:"int16,omitempty"` Int32 optional.Int32 `xml:"int32,omitempty"` Int64 optional.Int64 `xml:"int64,omitempty"` Int optional.Int `xml:"int,omitempty"` Rune optional.Rune `xml:"rune,omitempty"` String optional.String `xml:"string,omitempty"` Time optional.Time `xml:"time,omitempty"` Uint16 optional.Uint16 `xml:"uint16,omitempty"` Uint32 optional.Uint32 `xml:"uint32,omitempty"` Uint64 optional.Uint64 `xml:"uint64,omitempty"` Uint optional.Uint `xml:"uint,omitempty"` Uintptr optional.Uintptr `xml:"uintptr,omitempty"` }{ Bool: optional.EmptyBool(), Byte: optional.EmptyByte(), Float32: optional.EmptyFloat32(), Float64: optional.EmptyFloat64(), Int16: optional.EmptyInt16(), Int32: optional.EmptyInt32(), Int64: optional.EmptyInt64(), Int: optional.EmptyInt(), Rune: optional.EmptyRune(), String: optional.EmptyString(), Time: optional.EmptyTime(), Uint16: optional.EmptyUint16(), Uint32: optional.EmptyUint32(), Uint64: optional.EmptyUint64(), Uint: optional.EmptyUint(), Uintptr: optional.EmptyUintptr(), } output, _ := xml.MarshalIndent(s, "", " ") fmt.Println(string(output)) }
Output: <s></s>
Example (XmlMarshalPresent) ¶
package main import ( "encoding/xml" "fmt" "time" "4d63.com/optional" ) func main() { s := struct { XMLName xml.Name `xml:"s"` Bool optional.Bool `xml:"bool"` Byte optional.Byte `xml:"byte"` Float32 optional.Float32 `xml:"float32"` Float64 optional.Float64 `xml:"float64"` Int16 optional.Int16 `xml:"int16"` Int32 optional.Int32 `xml:"int32"` Int64 optional.Int64 `xml:"int64"` Int optional.Int `xml:"int"` Rune optional.Rune `xml:"rune"` String optional.String `xml:"string"` Time optional.Time `xml:"time"` Uint16 optional.Uint16 `xml:"uint16"` Uint32 optional.Uint32 `xml:"uint32"` Uint64 optional.Uint64 `xml:"uint64"` Uint optional.Uint `xml:"uint"` Uintptr optional.Uintptr `xml:"uintptr"` }{ Bool: optional.OfBool(true), Byte: optional.OfByte(1), Float32: optional.OfFloat32(2.1), Float64: optional.OfFloat64(2.2), Int16: optional.OfInt16(3), Int32: optional.OfInt32(4), Int64: optional.OfInt64(5), Int: optional.OfInt(6), Rune: optional.OfRune(7), String: optional.OfString("string"), Time: optional.OfTime(time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC)), Uint16: optional.OfUint16(8), Uint32: optional.OfUint32(9), Uint64: optional.OfUint64(10), Uint: optional.OfUint(11), Uintptr: optional.OfUintptr(12), } output, _ := xml.MarshalIndent(s, "", " ") fmt.Println(string(output)) }
Output: <s> <bool>true</bool> <byte>1</byte> <float32>2.1</float32> <float64>2.2</float64> <int16>3</int16> <int32>4</int32> <int64>5</int64> <int>6</int> <rune>7</rune> <string>string</string> <time>2006-01-02T15:04:05Z</time> <uint16>8</uint16> <uint32>9</uint32> <uint64>10</uint64> <uint>11</uint> <uintptr>12</uintptr> </s>
Example (XmlUnmarshalEmpty) ¶
package main import ( "encoding/xml" "fmt" "4d63.com/optional" ) func main() { s := struct { XMLName xml.Name `xml:"s"` Bool optional.Bool `xml:"bool"` Byte optional.Byte `xml:"byte"` Float32 optional.Float32 `xml:"float32"` Float64 optional.Float64 `xml:"float64"` Int16 optional.Int16 `xml:"int16"` Int32 optional.Int32 `xml:"int32"` Int64 optional.Int64 `xml:"int64"` Int optional.Int `xml:"int"` Rune optional.Rune `xml:"rune"` String optional.String `xml:"string"` Time optional.Time `xml:"time"` Uint16 optional.Uint16 `xml:"uint16"` Uint32 optional.Uint32 `xml:"uint32"` Uint64 optional.Uint64 `xml:"uint64"` Uint optional.Uint `xml:"uint"` Uintptr optional.Uintptr `xml:"uintptr"` }{} x := `<s></s>` xml.Unmarshal([]byte(x), &s) fmt.Println("Bool:", s.Bool.IsPresent()) fmt.Println("Byte:", s.Byte.IsPresent()) fmt.Println("Float32:", s.Float32.IsPresent()) fmt.Println("Float64:", s.Float64.IsPresent()) fmt.Println("Int16:", s.Int16.IsPresent()) fmt.Println("Int32:", s.Int32.IsPresent()) fmt.Println("Int64:", s.Int64.IsPresent()) fmt.Println("Int:", s.Int.IsPresent()) fmt.Println("Rune:", s.Rune.IsPresent()) fmt.Println("String:", s.String.IsPresent()) fmt.Println("Time:", s.Time.IsPresent()) fmt.Println("Uint16:", s.Uint16.IsPresent()) fmt.Println("Uint32:", s.Uint32.IsPresent()) fmt.Println("Uint64:", s.Uint64.IsPresent()) fmt.Println("Uint64:", s.Uint64.IsPresent()) fmt.Println("Uint:", s.Uint.IsPresent()) fmt.Println("Uintptr:", s.Uint.IsPresent()) }
Output: Bool: false Byte: false Float32: false Float64: false Int16: false Int32: false Int64: false Int: false Rune: false String: false Time: false Uint16: false Uint32: false Uint64: false Uint64: false Uint: false Uintptr: false
Example (XmlUnmarshalPresent) ¶
package main import ( "encoding/xml" "fmt" "4d63.com/optional" ) func main() { s := struct { XMLName xml.Name `xml:"s"` Bool optional.Bool `xml:"bool"` Byte optional.Byte `xml:"byte"` Float32 optional.Float32 `xml:"float32"` Float64 optional.Float64 `xml:"float64"` Int16 optional.Int16 `xml:"int16"` Int32 optional.Int32 `xml:"int32"` Int64 optional.Int64 `xml:"int64"` Int optional.Int `xml:"int"` Rune optional.Rune `xml:"rune"` String optional.String `xml:"string"` Time optional.Time `xml:"time"` Uint16 optional.Uint16 `xml:"uint16"` Uint32 optional.Uint32 `xml:"uint32"` Uint64 optional.Uint64 `xml:"uint64"` Uint optional.Uint `xml:"uint"` Uintptr optional.Uintptr `xml:"uintptr"` }{} x := `<s> <bool>false</bool> <byte>0</byte> <float32>0</float32> <float64>0</float64> <int16>0</int16> <int32>0</int32> <int64>0</int64> <int>0</int> <rune>0</rune> <string>string</string> <time>0001-01-01T00:00:00Z</time> <uint16>0</uint16> <uint32>0</uint32> <uint64>0</uint64> <uint>0</uint> <uintptr>0</uintptr> </s>` xml.Unmarshal([]byte(x), &s) fmt.Println("Bool:", s.Bool.IsPresent(), s.Bool) fmt.Println("Byte:", s.Byte.IsPresent(), s.Byte) fmt.Println("Float32:", s.Float32.IsPresent(), s.Float32) fmt.Println("Float64:", s.Float64.IsPresent(), s.Float64) fmt.Println("Int16:", s.Int16.IsPresent(), s.Int16) fmt.Println("Int32:", s.Int32.IsPresent(), s.Int32) fmt.Println("Int64:", s.Int64.IsPresent(), s.Int64) fmt.Println("Int:", s.Int.IsPresent(), s.Int) fmt.Println("Rune:", s.Rune.IsPresent(), s.Rune) fmt.Println("String:", s.String.IsPresent(), s.String) fmt.Println("Time:", s.Time.IsPresent(), s.Time) fmt.Println("Uint16:", s.Uint16.IsPresent(), s.Uint16) fmt.Println("Uint32:", s.Uint32.IsPresent(), s.Uint32) fmt.Println("Uint64:", s.Uint64.IsPresent(), s.Uint64) fmt.Println("Uint64:", s.Uint64.IsPresent(), s.Uint64) fmt.Println("Uint:", s.Uint.IsPresent(), s.Uint) fmt.Println("Uintptr:", s.Uint.IsPresent(), s.Uint) }
Output: Bool: true false Byte: true 0 Float32: true 0 Float64: true 0 Int16: true 0 Int32: true 0 Int64: true 0 Int: true 0 Rune: true 0 String: true string Time: true 0001-01-01 00:00:00 +0000 UTC Uint16: true 0 Uint32: true 0 Uint64: true 0 Uint64: true 0 Uint: true 0 Uintptr: true 0
Index ¶
- type Bool
- func (o Bool) Else(elseValue bool) (value bool)
- func (o Bool) ElseFunc(f func() bool) (value bool)
- func (o Bool) ElseZero() (value bool)
- func (o Bool) Get() (value bool, ok bool)
- func (o Bool) If(f func(value bool))
- func (o Bool) IsPresent() bool
- func (o Bool) MarshalJSON() (data []byte, err error)
- func (o Bool) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Bool) String() string
- func (o *Bool) UnmarshalJSON(data []byte) error
- func (o *Bool) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Byte
- func (o Byte) Else(elseValue byte) (value byte)
- func (o Byte) ElseFunc(f func() byte) (value byte)
- func (o Byte) ElseZero() (value byte)
- func (o Byte) Get() (value byte, ok bool)
- func (o Byte) If(f func(value byte))
- func (o Byte) IsPresent() bool
- func (o Byte) MarshalJSON() (data []byte, err error)
- func (o Byte) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Byte) String() string
- func (o *Byte) UnmarshalJSON(data []byte) error
- func (o *Byte) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Complex128
- func (o Complex128) Else(elseValue complex128) (value complex128)
- func (o Complex128) ElseFunc(f func() complex128) (value complex128)
- func (o Complex128) ElseZero() (value complex128)
- func (o Complex128) Get() (value complex128, ok bool)
- func (o Complex128) If(f func(value complex128))
- func (o Complex128) IsPresent() bool
- func (o Complex128) MarshalJSON() (data []byte, err error)
- func (o Complex128) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Complex128) String() string
- func (o *Complex128) UnmarshalJSON(data []byte) error
- func (o *Complex128) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Complex64
- func (o Complex64) Else(elseValue complex64) (value complex64)
- func (o Complex64) ElseFunc(f func() complex64) (value complex64)
- func (o Complex64) ElseZero() (value complex64)
- func (o Complex64) Get() (value complex64, ok bool)
- func (o Complex64) If(f func(value complex64))
- func (o Complex64) IsPresent() bool
- func (o Complex64) MarshalJSON() (data []byte, err error)
- func (o Complex64) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Complex64) String() string
- func (o *Complex64) UnmarshalJSON(data []byte) error
- func (o *Complex64) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Float32
- func (o Float32) Else(elseValue float32) (value float32)
- func (o Float32) ElseFunc(f func() float32) (value float32)
- func (o Float32) ElseZero() (value float32)
- func (o Float32) Get() (value float32, ok bool)
- func (o Float32) If(f func(value float32))
- func (o Float32) IsPresent() bool
- func (o Float32) MarshalJSON() (data []byte, err error)
- func (o Float32) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Float32) String() string
- func (o *Float32) UnmarshalJSON(data []byte) error
- func (o *Float32) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Float64
- func (o Float64) Else(elseValue float64) (value float64)
- func (o Float64) ElseFunc(f func() float64) (value float64)
- func (o Float64) ElseZero() (value float64)
- func (o Float64) Get() (value float64, ok bool)
- func (o Float64) If(f func(value float64))
- func (o Float64) IsPresent() bool
- func (o Float64) MarshalJSON() (data []byte, err error)
- func (o Float64) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Float64) String() string
- func (o *Float64) UnmarshalJSON(data []byte) error
- func (o *Float64) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Int
- func (o Int) Else(elseValue int) (value int)
- func (o Int) ElseFunc(f func() int) (value int)
- func (o Int) ElseZero() (value int)
- func (o Int) Get() (value int, ok bool)
- func (o Int) If(f func(value int))
- func (o Int) IsPresent() bool
- func (o Int) MarshalJSON() (data []byte, err error)
- func (o Int) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Int) String() string
- func (o *Int) UnmarshalJSON(data []byte) error
- func (o *Int) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Int16
- func (o Int16) Else(elseValue int16) (value int16)
- func (o Int16) ElseFunc(f func() int16) (value int16)
- func (o Int16) ElseZero() (value int16)
- func (o Int16) Get() (value int16, ok bool)
- func (o Int16) If(f func(value int16))
- func (o Int16) IsPresent() bool
- func (o Int16) MarshalJSON() (data []byte, err error)
- func (o Int16) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Int16) String() string
- func (o *Int16) UnmarshalJSON(data []byte) error
- func (o *Int16) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Int32
- func (o Int32) Else(elseValue int32) (value int32)
- func (o Int32) ElseFunc(f func() int32) (value int32)
- func (o Int32) ElseZero() (value int32)
- func (o Int32) Get() (value int32, ok bool)
- func (o Int32) If(f func(value int32))
- func (o Int32) IsPresent() bool
- func (o Int32) MarshalJSON() (data []byte, err error)
- func (o Int32) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Int32) String() string
- func (o *Int32) UnmarshalJSON(data []byte) error
- func (o *Int32) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Int64
- func (o Int64) Else(elseValue int64) (value int64)
- func (o Int64) ElseFunc(f func() int64) (value int64)
- func (o Int64) ElseZero() (value int64)
- func (o Int64) Get() (value int64, ok bool)
- func (o Int64) If(f func(value int64))
- func (o Int64) IsPresent() bool
- func (o Int64) MarshalJSON() (data []byte, err error)
- func (o Int64) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Int64) String() string
- func (o *Int64) UnmarshalJSON(data []byte) error
- func (o *Int64) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Int8
- func (o Int8) Else(elseValue int8) (value int8)
- func (o Int8) ElseFunc(f func() int8) (value int8)
- func (o Int8) ElseZero() (value int8)
- func (o Int8) Get() (value int8, ok bool)
- func (o Int8) If(f func(value int8))
- func (o Int8) IsPresent() bool
- func (o Int8) MarshalJSON() (data []byte, err error)
- func (o Int8) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Int8) String() string
- func (o *Int8) UnmarshalJSON(data []byte) error
- func (o *Int8) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Rune
- func (o Rune) Else(elseValue rune) (value rune)
- func (o Rune) ElseFunc(f func() rune) (value rune)
- func (o Rune) ElseZero() (value rune)
- func (o Rune) Get() (value rune, ok bool)
- func (o Rune) If(f func(value rune))
- func (o Rune) IsPresent() bool
- func (o Rune) MarshalJSON() (data []byte, err error)
- func (o Rune) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Rune) String() string
- func (o *Rune) UnmarshalJSON(data []byte) error
- func (o *Rune) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type String
- func (o String) Else(elseValue string) (value string)
- func (o String) ElseFunc(f func() string) (value string)
- func (o String) ElseZero() (value string)
- func (o String) Get() (value string, ok bool)
- func (o String) If(f func(value string))
- func (o String) IsPresent() bool
- func (o String) MarshalJSON() (data []byte, err error)
- func (o String) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o String) String() string
- func (o *String) UnmarshalJSON(data []byte) error
- func (o *String) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Time
- func (o Time) Else(elseValue time.Time) (value time.Time)
- func (o Time) ElseFunc(f func() time.Time) (value time.Time)
- func (o Time) ElseZero() (value time.Time)
- func (o Time) Get() (value time.Time, ok bool)
- func (o Time) If(f func(value time.Time))
- func (o Time) IsPresent() bool
- func (o Time) MarshalJSON() (data []byte, err error)
- func (o Time) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Time) String() string
- func (o *Time) UnmarshalJSON(data []byte) error
- func (o *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Uint
- func (o Uint) Else(elseValue uint) (value uint)
- func (o Uint) ElseFunc(f func() uint) (value uint)
- func (o Uint) ElseZero() (value uint)
- func (o Uint) Get() (value uint, ok bool)
- func (o Uint) If(f func(value uint))
- func (o Uint) IsPresent() bool
- func (o Uint) MarshalJSON() (data []byte, err error)
- func (o Uint) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Uint) String() string
- func (o *Uint) UnmarshalJSON(data []byte) error
- func (o *Uint) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Uint16
- func (o Uint16) Else(elseValue uint16) (value uint16)
- func (o Uint16) ElseFunc(f func() uint16) (value uint16)
- func (o Uint16) ElseZero() (value uint16)
- func (o Uint16) Get() (value uint16, ok bool)
- func (o Uint16) If(f func(value uint16))
- func (o Uint16) IsPresent() bool
- func (o Uint16) MarshalJSON() (data []byte, err error)
- func (o Uint16) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Uint16) String() string
- func (o *Uint16) UnmarshalJSON(data []byte) error
- func (o *Uint16) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Uint32
- func (o Uint32) Else(elseValue uint32) (value uint32)
- func (o Uint32) ElseFunc(f func() uint32) (value uint32)
- func (o Uint32) ElseZero() (value uint32)
- func (o Uint32) Get() (value uint32, ok bool)
- func (o Uint32) If(f func(value uint32))
- func (o Uint32) IsPresent() bool
- func (o Uint32) MarshalJSON() (data []byte, err error)
- func (o Uint32) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Uint32) String() string
- func (o *Uint32) UnmarshalJSON(data []byte) error
- func (o *Uint32) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Uint64
- func (o Uint64) Else(elseValue uint64) (value uint64)
- func (o Uint64) ElseFunc(f func() uint64) (value uint64)
- func (o Uint64) ElseZero() (value uint64)
- func (o Uint64) Get() (value uint64, ok bool)
- func (o Uint64) If(f func(value uint64))
- func (o Uint64) IsPresent() bool
- func (o Uint64) MarshalJSON() (data []byte, err error)
- func (o Uint64) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Uint64) String() string
- func (o *Uint64) UnmarshalJSON(data []byte) error
- func (o *Uint64) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Uint8
- func (o Uint8) Else(elseValue uint8) (value uint8)
- func (o Uint8) ElseFunc(f func() uint8) (value uint8)
- func (o Uint8) ElseZero() (value uint8)
- func (o Uint8) Get() (value uint8, ok bool)
- func (o Uint8) If(f func(value uint8))
- func (o Uint8) IsPresent() bool
- func (o Uint8) MarshalJSON() (data []byte, err error)
- func (o Uint8) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Uint8) String() string
- func (o *Uint8) UnmarshalJSON(data []byte) error
- func (o *Uint8) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Uintptr
- func (o Uintptr) Else(elseValue uintptr) (value uintptr)
- func (o Uintptr) ElseFunc(f func() uintptr) (value uintptr)
- func (o Uintptr) ElseZero() (value uintptr)
- func (o Uintptr) Get() (value uintptr, ok bool)
- func (o Uintptr) If(f func(value uintptr))
- func (o Uintptr) IsPresent() bool
- func (o Uintptr) MarshalJSON() (data []byte, err error)
- func (o Uintptr) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Uintptr) String() string
- func (o *Uintptr) UnmarshalJSON(data []byte) error
- func (o *Uintptr) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
Examples ¶
- Package (Else)
- Package (ElseFunc)
- Package (ElseZero)
- Package (Get)
- Package (If)
- Package (JsonMarshalEmpty)
- Package (JsonMarshalOmitEmpty)
- Package (JsonMarshalPresent)
- Package (JsonUnmarshalEmpty)
- Package (JsonUnmarshalPresent)
- Package (XmlMarshalEmpty)
- Package (XmlMarshalOmitEmpty)
- Package (XmlMarshalPresent)
- Package (XmlUnmarshalEmpty)
- Package (XmlUnmarshalPresent)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bool ¶
type Bool optionalBool
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func (Bool) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Bool) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Bool) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Bool) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Bool) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Bool) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Bool) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Bool) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Byte ¶
type Byte optionalByte
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func (Byte) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Byte) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Byte) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Byte) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Byte) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Byte) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Byte) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Byte) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Complex128 ¶
type Complex128 optionalComplex128
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func OfComplex128 ¶
func OfComplex128(value complex128) Complex128
Of wraps the value in an optional.
func OfComplex128Ptr ¶
func OfComplex128Ptr(ptr *complex128) Complex128
func (Complex128) Else ¶
func (o Complex128) Else(elseValue complex128) (value complex128)
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Complex128) ElseFunc ¶
func (o Complex128) ElseFunc(f func() complex128) (value complex128)
func (Complex128) ElseZero ¶
func (o Complex128) ElseZero() (value complex128)
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Complex128) Get ¶
func (o Complex128) Get() (value complex128, ok bool)
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Complex128) If ¶
func (o Complex128) If(f func(value complex128))
If calls the function if there is a value wrapped by this optional.
func (Complex128) IsPresent ¶
func (o Complex128) IsPresent() bool
IsPresent returns true if there is a value wrapped by this optional.
func (Complex128) MarshalJSON ¶
func (o Complex128) MarshalJSON() (data []byte, err error)
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Complex128) MarshalXML ¶
func (o Complex128) MarshalXML(e *xml.Encoder, start xml.StartElement) error
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Complex128) String ¶
func (o Complex128) String() string
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Complex128) UnmarshalJSON ¶
func (o *Complex128) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Complex128) UnmarshalXML ¶
func (o *Complex128) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Complex64 ¶
type Complex64 optionalComplex64
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func OfComplex64Ptr ¶
func (Complex64) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Complex64) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Complex64) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Complex64) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Complex64) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Complex64) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Complex64) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Complex64) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Float32 ¶
type Float32 optionalFloat32
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func OfFloat32Ptr ¶
func (Float32) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Float32) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Float32) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Float32) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Float32) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Float32) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Float32) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Float32) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Float64 ¶
type Float64 optionalFloat64
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func OfFloat64Ptr ¶
func (Float64) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Float64) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Float64) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Float64) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Float64) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Float64) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Float64) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Float64) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Int ¶
type Int optionalInt
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func (Int) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Int) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Int) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Int) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Int) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Int) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Int) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Int) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Int16 ¶
type Int16 optionalInt16
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func OfInt16Ptr ¶
func (Int16) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Int16) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Int16) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Int16) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Int16) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Int16) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Int16) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Int16) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Int32 ¶
type Int32 optionalInt32
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func OfInt32Ptr ¶
func (Int32) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Int32) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Int32) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Int32) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Int32) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Int32) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Int32) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Int32) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Int64 ¶
type Int64 optionalInt64
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func OfInt64Ptr ¶
func (Int64) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Int64) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Int64) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Int64) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Int64) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Int64) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Int64) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Int64) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Int8 ¶
type Int8 optionalInt8
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func (Int8) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Int8) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Int8) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Int8) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Int8) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Int8) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Int8) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Int8) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Rune ¶
type Rune optionalRune
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func (Rune) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Rune) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Rune) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Rune) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Rune) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Rune) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Rune) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Rune) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type String ¶
type String optionalString
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func OfStringPtr ¶
func (String) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (String) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (String) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (String) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (String) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (String) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*String) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*String) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Time ¶
type Time optionalTime
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func (Time) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Time) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Time) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Time) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Time) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Time) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Time) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Uint ¶
type Uint optionalUint
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func (Uint) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Uint) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Uint) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Uint) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Uint) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Uint) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Uint) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Uint) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Uint16 ¶
type Uint16 optionalUint16
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func OfUint16Ptr ¶
func (Uint16) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Uint16) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Uint16) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Uint16) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Uint16) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Uint16) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Uint16) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Uint16) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Uint32 ¶
type Uint32 optionalUint32
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func OfUint32Ptr ¶
func (Uint32) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Uint32) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Uint32) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Uint32) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Uint32) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Uint32) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Uint32) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Uint32) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Uint64 ¶
type Uint64 optionalUint64
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func OfUint64Ptr ¶
func (Uint64) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Uint64) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Uint64) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Uint64) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Uint64) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Uint64) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Uint64) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Uint64) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Uint8 ¶
type Uint8 optionalUint8
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func OfUint8Ptr ¶
func (Uint8) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Uint8) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Uint8) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Uint8) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Uint8) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Uint8) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Uint8) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Uint8) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
type Uintptr ¶
type Uintptr optionalUintptr
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func OfUintptrPtr ¶
func (Uintptr) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Uintptr) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Uintptr) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Uintptr) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Uintptr) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Uintptr) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Uintptr) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Uintptr) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.
Source Files
¶
- bool_generated.go
- byte_generated.go
- complex128_generated.go
- complex64_generated.go
- doc.go
- float32_generated.go
- float64_generated.go
- int16_generated.go
- int32_generated.go
- int64_generated.go
- int8_generated.go
- int_generated.go
- rune_generated.go
- string_generated.go
- time_generated.go
- types.go
- uint16_generated.go
- uint32_generated.go
- uint64_generated.go
- uint8_generated.go
- uint_generated.go
- uintptr_generated.go