RussellLuo / structool

A codec for Go structs with support for chainable encoding/decoding hooks.

Home Page:https://pkg.go.dev/github.com/RussellLuo/structool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

structool

A codec for Go structs with support for chainable encoding/decoding hooks.

Features

  1. Provide a uniform codec by combining mapstructure and structs.
  2. Make encoding/decoding hooks chainable.

Installation

$ go get -u github.com/RussellLuo/structool

Why?!

  1. Why to use structs

    mapstructure has limited support for decoding structs into maps (issues/166 and issues/249).

  2. Why to make a fork of fatih/structs

    fatih/structs has been archived, but it does not support encoding hooks yet.

  3. Why chainable hooks may be useful

    Both mapstructure and structs 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.

License

MIT

About

A codec for Go structs with support for chainable encoding/decoding hooks.

https://pkg.go.dev/github.com/RussellLuo/structool

License:MIT License


Languages

Language:Go 100.0%