Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jackc/structify
https://github.com/jackc/structify
Last synced: 24 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jackc/structify
- Owner: jackc
- License: mit
- Created: 2023-01-21T19:33:30.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-02-18T21:38:01.000Z (over 1 year ago)
- Last Synced: 2024-06-20T06:39:10.915Z (5 months ago)
- Language: Go
- Size: 33.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Go Reference](https://pkg.go.dev/badge/github.com/jackc/structify.svg)](https://pkg.go.dev/github.com/jackc/structify)
![Build Status](https://github.com/jackc/structify/actions/workflows/ci.yml/badge.svg)# structify
structify is designed to parse loosely-typed, client-controlled input such as JSON or a web form submission into a
struct. It's purpose is to validate input shape and convert to a struct, not to validate input contents. For example,
validating and converting an input field to an integer, not validating that the integer is between 0 and 10.## Example Usage
```go
type Person struct {
FirstName string
LastName string
}var person Person
err := structify.Parse(map[string]any{"FirstName": "John", "LastName": "Smith"}, &person)
```## Features
* Supports nested structs
* Supports slices
* Automatically maps between camelcase and snakecase. That is, `first_name` will be mapped to `FirstName` without needing a struct field tag
* Structured errors that accumulate all field errors
* Automatically uses database/sql.Scanner interface if available
* Can define scanner method on types or register on parser when not convenient to add method to type
* Includes generic Optional type