github.com/samsalisbury/is

Package is provides assertions on golang reflect types and values.


License
MIT
Install
go get github.com/samsalisbury/is

Documentation

is – Reflective Assertions for Golang

CircleCI codecov Go Report Card GoDoc License MIT

Package is provides some assertions on reflect.Values and reflect.Types.

Go's reflect package can sometimes leave one asking basic questions, like

Is this a zero value? Is this field exported?

Although there are well-documented ways to answer these kinds of questions, discoverability can be hard.

I hope this package comes in handy for quick and dirty assertions, but would encourage you to use this code as inspiration to writing your own reflect code accurately and hopefully more efficiently.

Is this a zero value?

  • is.Zero checks if a value is equal to the zero value of its underlying type.
  • is.ZeroForType checks if a value is equal to the zero value of the provided type.

These two functions are subtly different, check out the examples on godoc.

TODO

  • is.ExportedField(reflect.StructField)
  • is.ExportedType(reflect.Type)