structool
A codec for Go structs with support for chainable encoding/decoding hooks.
Features
- Provide a uniform codec by combining mapstructure and structs.
- Make encoding/decoding hooks chainable.
Installation
$ go get -u github.com/RussellLuo/structool
Why?!
-
Why to use
structs
mapstructure
has limited support for decoding structs into maps (issues/166 and issues/249). -
Why to make a fork of
fatih/structs
fatih/structs has been archived, but it does not support encoding hooks yet.
-
Why chainable hooks may be useful
Both
mapstructure
andstructs
support 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.
Documentation
Check out the Godoc.