An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 8.6% on proxy.golang.org
Top 7.0% forks on proxy.golang.org

proxy.golang.org : github.com/Southclaws/go-optional

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. Wrap a pointer in an optional: Unwrap it safely: Or get it's value with a fallback to a default: XML and JSON are supported out of the box. Use `omitempty` to omit the field when the optional is empty: Use the Optional template for your own types by installing gotemplate. Then add a `go generate` comment for your type to any `.go` file in your package. See the examples for more approaches to use.

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/%21southclaws/go-optional
License: MIT
Latest release: almost 3 years ago
First release: about 4 years ago
Namespace: github.com/Southclaws
Stars: 0 on GitHub
Forks: 1 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 29 days ago

    Loading...
    Readme
    Loading...