Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/reiver/gogen-optiontype

Option types (also known as maybe types) for Go, via "go generate".
https://github.com/reiver/gogen-optiontype

go-generate go-generics option-type

Last synced: about 1 month ago
JSON representation

Option types (also known as maybe types) for Go, via "go generate".

Awesome Lists containing this project

README

        

# gogen-optiontype

Option types (also known as maybe types) for Go programming language, via `go generate`.

# Usage

```go
package itemid

//go:generate gogen-optiontype --pkg=itemid --type=int64

```

```go
package thingid

//go:generate gogen-optiontype --pkg=thingid --type=string --one-file

```

```go
package productid

//go:generate gogen-optiontype --pkg=thingid --type=string --one-file --no-tests

```

And then run:
```
go generate
```
or:
```
gb generate
```
(If you are using [GB](https://getgb.io/).)

Can then use with code similar to:
```
type Struct Product {
ID productid.Type
Name string
ItemID itemid.NullableType
}
```