A codec for Go structs with support for chainable encoding/decoding hooks.
- Provide a uniform codec by combining mapstructure and structs.
- Make encoding/decoding hooks chainable.
$ go get -u github.com/RussellLuo/structool-
Why to use
structsmapstructurehas limited support for decoding structs into maps (issues/166 and issues/249). -
Why to make a fork of
fatih/structsfatih/structs has been archived, but it does not support encoding hooks yet.
-
Why chainable hooks may be useful
Both
mapstructureandstructssupport hooks in the form of a single function. While this keeps the libraries themselves simple, it forces us to couple various conversions together.Chainable hooks (like HTTP middlewares), on the other hand, promote separation of concerns, and thus make individual hooks reusable and composable.
Check out the Godoc.