v0.1.0 — Optional types for Go
First Release
opt — Go-idiomatic Option<T> with full SQL + JSON integration.
Highlights
- Generic
Value[T]— foundation onsql.Null[T](Go 1.24+) - 9 concrete types — String, Int, Int32, Int16, Float, Bool, Byte, Time
Field[T]— three-state (absent/null/value) for PATCH API — unique in Go ecosystem- Functional API —
Map,FlatMap,Equal zero/subpackage — alternative semantics (zero value = null)- Zero-allocation unmarshal, Bool marshal <1ns
encoding/json/v2compatible- Stdlib only — zero external dependencies
Install
go get github.com/coregx/opt@v0.1.0Quick Start
name := opt.StringFrom("Alice")
age := opt.NewInt(0, false) // null
fmt.Println(name.Or("unknown")) // "Alice"
fmt.Println(age.OrZero()) // 0
data, _ := json.Marshal(struct {
Name opt.String `json:"name"`
Age opt.Int `json:"age"`
}{name, age})
// {"name":"Alice","age":null}Full documentation: README | pkg.go.dev