Go libraries, Open source
xMapper
Struct validation and mapping library for Go
A Go library that validates data and maps it from one struct to another, transforming fields along the way.

Stack
- Go
- Open source
- Library
- Status
- Open source
- Type
- Go libraries
- Source
- GitHub
The problem
Copying fields from one Go struct to another by hand is repetitive and easy to get wrong.
What it does
xMapper automates mapping between Go structs. It validates the data and transforms values dynamically as they move from source to destination. Its behavior is customizable.
How it's built
A Go library using Go modules (Go 1.11+), open source on GitHub.
Key features
- Struct-to-struct mapping
- Validation rules and transformers declared in struct tags, for example validators:"email" and transformers:"trim,lowercase"
- Validate a single struct without mapping, with a typed validation error (xmapper.ErrValidation)
- Dynamic transforms as data flows from source to destination
- Customizable to your needs
Install and usage
Install
go get github.com/dev3mike/go-xmappergo
type User struct {
Email string `json:"email" validators:"email" transformers:"trim,lowercase"`
}
user := User{Email: "[email protected]"}
// Call ValidateStruct to check validation.
err := xmapper.ValidateStruct(&user)
// Check error type for validation errors
if errors.Is(err, xmapper.ErrValidation) {
// Return bad request or ...
}Screens

Validate and map JSON into a struct
Contact
Want something like this built?