Skip to content

gomoni/null

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License

null

null is a Go library providing an easy to use interface to handle null value or missing key. Type[T any] implements json.Marshaler and json.Unmarshaler . Because of generics it works for any type which can be unmarshalled from/marshalled into JSON.

Marshalling of undefined is an error though.

Usage

// define struct with a wrapper type
var s struct {
    Key Type[int] `json:"key"`
}
// unmarshal as usual
err := json.Unmarshal(data, &s)
// access value via Value() method, which returns error for null and undefined cases
value, err := s.Key.Value()
JSON Value Error
{"key": 42} 42 nil
{"key": null} zero ErrNull
{} zero ErrUndefined

Build and test

install gotip (until go 1.18 release)

go install golang.org/dl/gotip@latest
gotip download
gotip test -v

Releases

No releases published

Packages

No packages published

Languages