type-errors

command
Version: v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 3 Imported by: 0

README

This example shows how you might generate a JSON response if the client's request has some type errors.

Model

type Address struct {
	Country     string `json:"country"`
	City        string `json:"city"`
	AddressLine string `json:"address_line"`
}

type Person struct {
	FirstName string  `json:"first_name"`
	LastName  string  `json:"last_name"`
	Age       int     `json:"age"`
	Address   Address `json:"address"`
}

Input

{
	"first_name": "Jessie",
	"age": "26",
	"address": {
		"country": "US",
		"city": null
	}
}

Output

missing fields:    [last_name address.address_line]
mismatched fields: [expected "age" to be an int but it's a string expected "address.city" to be a string but it's null]
{
    "errors": {
        "address": {
            "city": "expected a string but it's null"
        },
        "age": "expected an int but it's a string"
    },
    "ok": false
}

Documentation

The Go Gopher

There is no documentation for this package.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL