optional

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2018 License: MIT Imports: 2 Imported by: 0

README

Optional

Build Status Release Software License Go Doc Go Report Card SayThanks.io

Optional is a tool that generates 'optional' type wrappers around a given type T.

It is also a library that provides optional types for the primitive Go types.

Motivation

Ever had to write a test where you want to assert something only if a value is present?

tests :=  []struct {
  data string
  dataPresent bool
} {
    { "YOLO kombucha slow-carb wayfarers fixie", true },
    { "", false },
}

...

if test.dataPresent {
  assert.Equal(t, hipsterism, test.data)
}

Now you can simplify all that with optional types:

tests :=  []struct {
  data optional.String
} {
    { optional.NewString("viral narwhal etsy twee VHS") },
    { optional.String{} },
  }
}

...

test.data.If(func(s string) {
    assert.Equal(t, hipsterism, s)
})

Marshalling/Unmarshalling JSON

Optional types also marshal to/from JSON as you would expect:

Marshalling
func main() {
  var value = struct {
    Field optional.String `json:"field,omitempty"`
  }{
    Field: optional.NewString("bar"),
  }

  out, _ := json.Marshal(value)
  fmt.Println(string(out))
  // outputs: {"field":"bar"}
}
Unmarshalling
func main() {
  var value = &struct {
    Field optional.String `json:"field,omitempty"`
  }{}

  _ = json.Unmarshal([]byte(`{"field":"bar"}`), value)

  value.Field.If(func(s string) {
    fmt.Println(s)
  })
  // outputs: bar
}

See example_test.go for more examples.

Inspiration

Tool

Install

go get -u github.com/markphelps/optional/cmd/optional

Usage

Typically this process would be run using go generate, like this:

//go:generate optional -type=Foo

running this command:

optional -type=Foo

in the same directory will create the file optional_foo.go containing a definition of:

type OptionalFoo struct {
  ...
}

The default type is OptionalT or optionalT (depending on if the type is exported) and output file is optional_t.go. This can be overridden with the -output flag.

Library

Usage
import (
  "fmt"

  "github.com/markphelps/optional"
)

s := optional.NewString("foo")

if s.Present() {
  value, _ := s.Get()
  fmt.Println(value)
}

t := optional.String{}
fmt.Println(t.OrElse("bar"))

See example_test.go and the documentation for more usage.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Documentation

Overview

Example (Get)
package main

import (
	"fmt"

	"github.com/markphelps/optional"
)

func main() {
	values := []optional.String{
		optional.NewString("foo"),
		optional.NewString(""),
		optional.NewString("bar"),
		{},
	}

	for _, v := range values {
		if v.Present() {
			value, err := v.Get()
			if err == nil {
				fmt.Println(value)
			}
		}
	}

}
Output:

foo

bar
Example (If)
package main

import (
	"fmt"

	"github.com/markphelps/optional"
)

func main() {
	values := []optional.String{
		optional.NewString("foo"),
		optional.NewString(""),
		optional.NewString("bar"),
		{},
	}

	for _, v := range values {
		v.If(func(s string) {
			fmt.Println("present")
		})
	}

}
Output:

present
present
present
Example (MarshalJSON)
package main

import (
	"encoding/json"
	"fmt"

	"github.com/markphelps/optional"
)

func main() {
	type example struct {
		Field *optional.String `json:"field,omitempty"`
	}

	var values = []optional.String{
		optional.NewString("foo"),
		optional.NewString(""),
		optional.NewString("bar"),
	}

	for _, v := range values {
		out, _ := json.Marshal(&example{
			Field: &v,
		})
		fmt.Println(string(out))
	}

}
Output:

{"field":"foo"}
{"field":""}
{"field":"bar"}
Example (OrElse)
package main

import (
	"fmt"

	"github.com/markphelps/optional"
)

func main() {
	values := []optional.String{
		optional.NewString("foo"),
		optional.NewString(""),
		optional.NewString("bar"),
		{},
	}

	for _, v := range values {
		fmt.Println(v.OrElse("not present"))
	}

}
Output:

foo

bar
not present
Example (UnmarshalJSON)
package main

import (
	"encoding/json"
	"fmt"

	"github.com/markphelps/optional"
)

func main() {
	var values = []string{
		`{"field":"foo"}`,
		`{"field":""}`,
		`{"field":"bar"}`,
		"{}",
	}

	for _, v := range values {
		var o = &struct {
			Field optional.String `json:"field,omitempty"`
		}{}

		if err := json.Unmarshal([]byte(v), o); err != nil {
			fmt.Println(err)
		}

		o.Field.If(func(s string) {
			fmt.Println(s)
		})
	}

}
Output:

foo

bar

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool struct {
	// contains filtered or unexported fields
}

Bool is an optional bool

func NewBool added in v0.3.0

func NewBool(v bool) Bool

NewBool creates a optional.Bool from a bool

func (Bool) Get

func (b Bool) Get() (bool, error)

Get returns the bool value or an error if not present

func (Bool) If added in v0.2.0

func (b Bool) If(fn func(bool))

If calls the function f with the value if the value is present

func (Bool) MarshalJSON added in v0.4.0

func (b Bool) MarshalJSON() ([]byte, error)

func (Bool) OrElse

func (b Bool) OrElse(v bool) bool

OrElse returns the bool value or a default value if the value is not present

func (Bool) Present

func (b Bool) Present() bool

Present returns whether or not the value is present

func (Bool) Set

func (b Bool) Set(v bool)

Set sets the bool value

func (*Bool) UnmarshalJSON added in v0.4.0

func (b *Bool) UnmarshalJSON(data []byte) error

type Byte

type Byte struct {
	// contains filtered or unexported fields
}

Byte is an optional byte

func NewByte added in v0.3.0

func NewByte(v byte) Byte

NewByte creates a optional.Byte from a byte

func (Byte) Get

func (b Byte) Get() (byte, error)

Get returns the byte value or an error if not present

func (Byte) If added in v0.2.0

func (b Byte) If(fn func(byte))

If calls the function f with the value if the value is present

func (Byte) MarshalJSON added in v0.4.0

func (b Byte) MarshalJSON() ([]byte, error)

func (Byte) OrElse

func (b Byte) OrElse(v byte) byte

OrElse returns the byte value or a default value if the value is not present

func (Byte) Present

func (b Byte) Present() bool

Present returns whether or not the value is present

func (Byte) Set

func (b Byte) Set(v byte)

Set sets the byte value

func (*Byte) UnmarshalJSON added in v0.4.0

func (b *Byte) UnmarshalJSON(data []byte) error

type Complex128

type Complex128 struct {
	// contains filtered or unexported fields
}

Complex128 is an optional complex128

func NewComplex128 added in v0.3.0

func NewComplex128(v complex128) Complex128

NewComplex128 creates a optional.Complex128 from a complex128

func (Complex128) Get

func (c Complex128) Get() (complex128, error)

Get returns the complex128 value or an error if not present

func (Complex128) If added in v0.2.0

func (c Complex128) If(fn func(complex128))

If calls the function f with the value if the value is present

func (Complex128) MarshalJSON added in v0.4.0

func (c Complex128) MarshalJSON() ([]byte, error)

func (Complex128) OrElse

func (c Complex128) OrElse(v complex128) complex128

OrElse returns the complex128 value or a default value if the value is not present

func (Complex128) Present

func (c Complex128) Present() bool

Present returns whether or not the value is present

func (Complex128) Set

func (c Complex128) Set(v complex128)

Set sets the complex128 value

func (*Complex128) UnmarshalJSON added in v0.4.0

func (c *Complex128) UnmarshalJSON(data []byte) error

type Complex64

type Complex64 struct {
	// contains filtered or unexported fields
}

Complex64 is an optional complex64

func NewComplex64 added in v0.3.0

func NewComplex64(v complex64) Complex64

NewComplex64 creates a optional.Complex64 from a complex64

func (Complex64) Get

func (c Complex64) Get() (complex64, error)

Get returns the complex64 value or an error if not present

func (Complex64) If added in v0.2.0

func (c Complex64) If(fn func(complex64))

If calls the function f with the value if the value is present

func (Complex64) MarshalJSON added in v0.4.0

func (c Complex64) MarshalJSON() ([]byte, error)

func (Complex64) OrElse

func (c Complex64) OrElse(v complex64) complex64

OrElse returns the complex64 value or a default value if the value is not present

func (Complex64) Present

func (c Complex64) Present() bool

Present returns whether or not the value is present

func (Complex64) Set

func (c Complex64) Set(v complex64)

Set sets the complex64 value

func (*Complex64) UnmarshalJSON added in v0.4.0

func (c *Complex64) UnmarshalJSON(data []byte) error

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is an optional error

func NewError added in v0.3.0

func NewError(v error) Error

NewError creates a optional.Error from a error

func (Error) Get

func (e Error) Get() (error, error)

Get returns the error value or an error if not present

func (Error) If added in v0.2.0

func (e Error) If(fn func(error))

If calls the function f with the value if the value is present

func (Error) MarshalJSON added in v0.4.0

func (e Error) MarshalJSON() ([]byte, error)

func (Error) OrElse

func (e Error) OrElse(v error) error

OrElse returns the error value or a default value if the value is not present

func (Error) Present

func (e Error) Present() bool

Present returns whether or not the value is present

func (Error) Set

func (e Error) Set(v error)

Set sets the error value

func (*Error) UnmarshalJSON added in v0.4.0

func (e *Error) UnmarshalJSON(data []byte) error

type Float32

type Float32 struct {
	// contains filtered or unexported fields
}

Float32 is an optional float32

func NewFloat32 added in v0.3.0

func NewFloat32(v float32) Float32

NewFloat32 creates a optional.Float32 from a float32

func (Float32) Get

func (f Float32) Get() (float32, error)

Get returns the float32 value or an error if not present

func (Float32) If added in v0.2.0

func (f Float32) If(fn func(float32))

If calls the function f with the value if the value is present

func (Float32) MarshalJSON added in v0.4.0

func (f Float32) MarshalJSON() ([]byte, error)

func (Float32) OrElse

func (f Float32) OrElse(v float32) float32

OrElse returns the float32 value or a default value if the value is not present

func (Float32) Present

func (f Float32) Present() bool

Present returns whether or not the value is present

func (Float32) Set

func (f Float32) Set(v float32)

Set sets the float32 value

func (*Float32) UnmarshalJSON added in v0.4.0

func (f *Float32) UnmarshalJSON(data []byte) error

type Float64

type Float64 struct {
	// contains filtered or unexported fields
}

Float64 is an optional float64

func NewFloat64 added in v0.3.0

func NewFloat64(v float64) Float64

NewFloat64 creates a optional.Float64 from a float64

func (Float64) Get

func (f Float64) Get() (float64, error)

Get returns the float64 value or an error if not present

func (Float64) If added in v0.2.0

func (f Float64) If(fn func(float64))

If calls the function f with the value if the value is present

func (Float64) MarshalJSON added in v0.4.0

func (f Float64) MarshalJSON() ([]byte, error)

func (Float64) OrElse

func (f Float64) OrElse(v float64) float64

OrElse returns the float64 value or a default value if the value is not present

func (Float64) Present

func (f Float64) Present() bool

Present returns whether or not the value is present

func (Float64) Set

func (f Float64) Set(v float64)

Set sets the float64 value

func (*Float64) UnmarshalJSON added in v0.4.0

func (f *Float64) UnmarshalJSON(data []byte) error

type Int

type Int struct {
	// contains filtered or unexported fields
}

Int is an optional int

func NewInt added in v0.3.0

func NewInt(v int) Int

NewInt creates a optional.Int from a int

func (Int) Get

func (i Int) Get() (int, error)

Get returns the int value or an error if not present

func (Int) If added in v0.2.0

func (i Int) If(fn func(int))

If calls the function f with the value if the value is present

func (Int) MarshalJSON added in v0.4.0

func (i Int) MarshalJSON() ([]byte, error)

func (Int) OrElse

func (i Int) OrElse(v int) int

OrElse returns the int value or a default value if the value is not present

func (Int) Present

func (i Int) Present() bool

Present returns whether or not the value is present

func (Int) Set

func (i Int) Set(v int)

Set sets the int value

func (*Int) UnmarshalJSON added in v0.4.0

func (i *Int) UnmarshalJSON(data []byte) error

type Int16

type Int16 struct {
	// contains filtered or unexported fields
}

Int16 is an optional int16

func NewInt16 added in v0.3.0

func NewInt16(v int16) Int16

NewInt16 creates a optional.Int16 from a int16

func (Int16) Get

func (i Int16) Get() (int16, error)

Get returns the int16 value or an error if not present

func (Int16) If added in v0.2.0

func (i Int16) If(fn func(int16))

If calls the function f with the value if the value is present

func (Int16) MarshalJSON added in v0.4.0

func (i Int16) MarshalJSON() ([]byte, error)

func (Int16) OrElse

func (i Int16) OrElse(v int16) int16

OrElse returns the int16 value or a default value if the value is not present

func (Int16) Present

func (i Int16) Present() bool

Present returns whether or not the value is present

func (Int16) Set

func (i Int16) Set(v int16)

Set sets the int16 value

func (*Int16) UnmarshalJSON added in v0.4.0

func (i *Int16) UnmarshalJSON(data []byte) error

type Int32

type Int32 struct {
	// contains filtered or unexported fields
}

Int32 is an optional int32

func NewInt32 added in v0.3.0

func NewInt32(v int32) Int32

NewInt32 creates a optional.Int32 from a int32

func (Int32) Get

func (i Int32) Get() (int32, error)

Get returns the int32 value or an error if not present

func (Int32) If added in v0.2.0

func (i Int32) If(fn func(int32))

If calls the function f with the value if the value is present

func (Int32) MarshalJSON added in v0.4.0

func (i Int32) MarshalJSON() ([]byte, error)

func (Int32) OrElse

func (i Int32) OrElse(v int32) int32

OrElse returns the int32 value or a default value if the value is not present

func (Int32) Present

func (i Int32) Present() bool

Present returns whether or not the value is present

func (Int32) Set

func (i Int32) Set(v int32)

Set sets the int32 value

func (*Int32) UnmarshalJSON added in v0.4.0

func (i *Int32) UnmarshalJSON(data []byte) error

type Int64

type Int64 struct {
	// contains filtered or unexported fields
}

Int64 is an optional int64

func NewInt64 added in v0.3.0

func NewInt64(v int64) Int64

NewInt64 creates a optional.Int64 from a int64

func (Int64) Get

func (i Int64) Get() (int64, error)

Get returns the int64 value or an error if not present

func (Int64) If added in v0.2.0

func (i Int64) If(fn func(int64))

If calls the function f with the value if the value is present

func (Int64) MarshalJSON added in v0.4.0

func (i Int64) MarshalJSON() ([]byte, error)

func (Int64) OrElse

func (i Int64) OrElse(v int64) int64

OrElse returns the int64 value or a default value if the value is not present

func (Int64) Present

func (i Int64) Present() bool

Present returns whether or not the value is present

func (Int64) Set

func (i Int64) Set(v int64)

Set sets the int64 value

func (*Int64) UnmarshalJSON added in v0.4.0

func (i *Int64) UnmarshalJSON(data []byte) error

type Int8

type Int8 struct {
	// contains filtered or unexported fields
}

Int8 is an optional int8

func NewInt8 added in v0.3.0

func NewInt8(v int8) Int8

NewInt8 creates a optional.Int8 from a int8

func (Int8) Get

func (i Int8) Get() (int8, error)

Get returns the int8 value or an error if not present

func (Int8) If added in v0.2.0

func (i Int8) If(fn func(int8))

If calls the function f with the value if the value is present

func (Int8) MarshalJSON added in v0.4.0

func (i Int8) MarshalJSON() ([]byte, error)

func (Int8) OrElse

func (i Int8) OrElse(v int8) int8

OrElse returns the int8 value or a default value if the value is not present

func (Int8) Present

func (i Int8) Present() bool

Present returns whether or not the value is present

func (Int8) Set

func (i Int8) Set(v int8)

Set sets the int8 value

func (*Int8) UnmarshalJSON added in v0.4.0

func (i *Int8) UnmarshalJSON(data []byte) error

type Rune

type Rune struct {
	// contains filtered or unexported fields
}

Rune is an optional rune

func NewRune added in v0.3.0

func NewRune(v rune) Rune

NewRune creates a optional.Rune from a rune

func (Rune) Get

func (r Rune) Get() (rune, error)

Get returns the rune value or an error if not present

func (Rune) If added in v0.2.0

func (r Rune) If(fn func(rune))

If calls the function f with the value if the value is present

func (Rune) MarshalJSON added in v0.4.0

func (r Rune) MarshalJSON() ([]byte, error)

func (Rune) OrElse

func (r Rune) OrElse(v rune) rune

OrElse returns the rune value or a default value if the value is not present

func (Rune) Present

func (r Rune) Present() bool

Present returns whether or not the value is present

func (Rune) Set

func (r Rune) Set(v rune)

Set sets the rune value

func (*Rune) UnmarshalJSON added in v0.4.0

func (r *Rune) UnmarshalJSON(data []byte) error

type String

type String struct {
	// contains filtered or unexported fields
}

String is an optional string

func NewString added in v0.3.0

func NewString(v string) String

NewString creates a optional.String from a string

func (String) Get

func (s String) Get() (string, error)

Get returns the string value or an error if not present

func (String) If added in v0.2.0

func (s String) If(fn func(string))

If calls the function f with the value if the value is present

func (String) MarshalJSON added in v0.4.0

func (s String) MarshalJSON() ([]byte, error)

func (String) OrElse

func (s String) OrElse(v string) string

OrElse returns the string value or a default value if the value is not present

func (String) Present

func (s String) Present() bool

Present returns whether or not the value is present

func (String) Set

func (s String) Set(v string)

Set sets the string value

func (*String) UnmarshalJSON added in v0.4.0

func (s *String) UnmarshalJSON(data []byte) error

type Uint

type Uint struct {
	// contains filtered or unexported fields
}

Uint is an optional uint

func NewUint added in v0.3.0

func NewUint(v uint) Uint

NewUint creates a optional.Uint from a uint

func (Uint) Get

func (u Uint) Get() (uint, error)

Get returns the uint value or an error if not present

func (Uint) If added in v0.2.0

func (u Uint) If(fn func(uint))

If calls the function f with the value if the value is present

func (Uint) MarshalJSON added in v0.4.0

func (u Uint) MarshalJSON() ([]byte, error)

func (Uint) OrElse

func (u Uint) OrElse(v uint) uint

OrElse returns the uint value or a default value if the value is not present

func (Uint) Present

func (u Uint) Present() bool

Present returns whether or not the value is present

func (Uint) Set

func (u Uint) Set(v uint)

Set sets the uint value

func (*Uint) UnmarshalJSON added in v0.4.0

func (u *Uint) UnmarshalJSON(data []byte) error

type Uint16

type Uint16 struct {
	// contains filtered or unexported fields
}

Uint16 is an optional uint16

func NewUint16 added in v0.3.0

func NewUint16(v uint16) Uint16

NewUint16 creates a optional.Uint16 from a uint16

func (Uint16) Get

func (u Uint16) Get() (uint16, error)

Get returns the uint16 value or an error if not present

func (Uint16) If added in v0.2.0

func (u Uint16) If(fn func(uint16))

If calls the function f with the value if the value is present

func (Uint16) MarshalJSON added in v0.4.0

func (u Uint16) MarshalJSON() ([]byte, error)

func (Uint16) OrElse

func (u Uint16) OrElse(v uint16) uint16

OrElse returns the uint16 value or a default value if the value is not present

func (Uint16) Present

func (u Uint16) Present() bool

Present returns whether or not the value is present

func (Uint16) Set

func (u Uint16) Set(v uint16)

Set sets the uint16 value

func (*Uint16) UnmarshalJSON added in v0.4.0

func (u *Uint16) UnmarshalJSON(data []byte) error

type Uint32

type Uint32 struct {
	// contains filtered or unexported fields
}

Uint32 is an optional uint32

func NewUint32 added in v0.3.0

func NewUint32(v uint32) Uint32

NewUint32 creates a optional.Uint32 from a uint32

func (Uint32) Get

func (u Uint32) Get() (uint32, error)

Get returns the uint32 value or an error if not present

func (Uint32) If added in v0.2.0

func (u Uint32) If(fn func(uint32))

If calls the function f with the value if the value is present

func (Uint32) MarshalJSON added in v0.4.0

func (u Uint32) MarshalJSON() ([]byte, error)

func (Uint32) OrElse

func (u Uint32) OrElse(v uint32) uint32

OrElse returns the uint32 value or a default value if the value is not present

func (Uint32) Present

func (u Uint32) Present() bool

Present returns whether or not the value is present

func (Uint32) Set

func (u Uint32) Set(v uint32)

Set sets the uint32 value

func (*Uint32) UnmarshalJSON added in v0.4.0

func (u *Uint32) UnmarshalJSON(data []byte) error

type Uint64

type Uint64 struct {
	// contains filtered or unexported fields
}

Uint64 is an optional uint64

func NewUint64 added in v0.3.0

func NewUint64(v uint64) Uint64

NewUint64 creates a optional.Uint64 from a uint64

func (Uint64) Get

func (u Uint64) Get() (uint64, error)

Get returns the uint64 value or an error if not present

func (Uint64) If added in v0.2.0

func (u Uint64) If(fn func(uint64))

If calls the function f with the value if the value is present

func (Uint64) MarshalJSON added in v0.4.0

func (u Uint64) MarshalJSON() ([]byte, error)

func (Uint64) OrElse

func (u Uint64) OrElse(v uint64) uint64

OrElse returns the uint64 value or a default value if the value is not present

func (Uint64) Present

func (u Uint64) Present() bool

Present returns whether or not the value is present

func (Uint64) Set

func (u Uint64) Set(v uint64)

Set sets the uint64 value

func (*Uint64) UnmarshalJSON added in v0.4.0

func (u *Uint64) UnmarshalJSON(data []byte) error

type Uint8

type Uint8 struct {
	// contains filtered or unexported fields
}

Uint8 is an optional uint8

func NewUint8 added in v0.3.0

func NewUint8(v uint8) Uint8

NewUint8 creates a optional.Uint8 from a uint8

func (Uint8) Get

func (u Uint8) Get() (uint8, error)

Get returns the uint8 value or an error if not present

func (Uint8) If added in v0.2.0

func (u Uint8) If(fn func(uint8))

If calls the function f with the value if the value is present

func (Uint8) MarshalJSON added in v0.4.0

func (u Uint8) MarshalJSON() ([]byte, error)

func (Uint8) OrElse

func (u Uint8) OrElse(v uint8) uint8

OrElse returns the uint8 value or a default value if the value is not present

func (Uint8) Present

func (u Uint8) Present() bool

Present returns whether or not the value is present

func (Uint8) Set

func (u Uint8) Set(v uint8)

Set sets the uint8 value

func (*Uint8) UnmarshalJSON added in v0.4.0

func (u *Uint8) UnmarshalJSON(data []byte) error

type Uintptr

type Uintptr struct {
	// contains filtered or unexported fields
}

Uintptr is an optional uintptr

func NewUintptr added in v0.3.0

func NewUintptr(v uintptr) Uintptr

NewUintptr creates a optional.Uintptr from a uintptr

func (Uintptr) Get

func (u Uintptr) Get() (uintptr, error)

Get returns the uintptr value or an error if not present

func (Uintptr) If added in v0.2.0

func (u Uintptr) If(fn func(uintptr))

If calls the function f with the value if the value is present

func (Uintptr) MarshalJSON added in v0.4.0

func (u Uintptr) MarshalJSON() ([]byte, error)

func (Uintptr) OrElse

func (u Uintptr) OrElse(v uintptr) uintptr

OrElse returns the uintptr value or a default value if the value is not present

func (Uintptr) Present

func (u Uintptr) Present() bool

Present returns whether or not the value is present

func (Uintptr) Set

func (u Uintptr) Set(v uintptr)

Set sets the uintptr value

func (*Uintptr) UnmarshalJSON added in v0.4.0

func (u *Uintptr) UnmarshalJSON(data []byte) error

Directories

Path Synopsis
cmd
optional
Optional is a tool that generates 'optional' type wrappers around a given type T. Typically this process would be run using go generate, like this: //go:generate optional -type=Foo running this command optional -type=Foo in the same directory will create the file optional_foo.go containing a definition of type OptionalFoo struct { ...
Optional is a tool that generates 'optional' type wrappers around a given type T. Typically this process would be run using go generate, like this: //go:generate optional -type=Foo running this command optional -type=Foo in the same directory will create the file optional_foo.go containing a definition of type OptionalFoo struct { ...

Jump to

Keyboard shortcuts

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