Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/AmuzaTkts/jsonapi-errors
Go bindings based on the JSON API errors reference
https://github.com/AmuzaTkts/jsonapi-errors
go golang json-api jsonapi-errors
Last synced: about 1 month ago
JSON representation
Go bindings based on the JSON API errors reference
- Host: GitHub
- URL: https://github.com/AmuzaTkts/jsonapi-errors
- Owner: AmuzaTkts
- License: mit
- Created: 2016-07-08T10:08:58.000Z (almost 8 years ago)
- Default Branch: develop
- Last Pushed: 2016-11-17T16:02:12.000Z (over 7 years ago)
- Last Synced: 2024-01-30T04:49:24.551Z (4 months ago)
- Topics: go, golang, json-api, jsonapi-errors
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 14
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Search and Analytic Databases)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Search and Analytic Databases)
- awesome-go-extra - jsonapi-errors - 07-08T10:08:58Z|2016-11-17T16:02:12Z| (JSON / Advanced Console UIs)
- awesome-go-zh - jsonapi-errors
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Search and Analytic Databases)
- awesome-go - jsonapi-errors - | - | - | (JSON / Advanced Console UIs)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Advanced Console UIs)
- awesome-go-projects - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Standard CLI)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Search and Analytic Databases)
- awesome-go-with-framework - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Advanced Console UIs)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Search and Analytic Databases)
- awesome-go-cn - jsonapi-errors - errors) [![godoc][D]](https://godoc.org/github.com/AmuzaTkts/jsonapi-errors) (JSON / 检索及分析资料库)
- awesome-go-stars - jsonapi-errors(stars: 14) - Go bindings based on the JSON API errors reference. (JSON / Search and Analytic Databases)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Advanced Console UIs)
- awesome-go. - jsonapi-errors - Go bindings based on the JSON API errors reference. (Utilities / Advanced Console UIs)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (Utilities / <span id="高级控制台用户界面-advanced-console-uis">高级控制台用户界面 Advanced Console UIs</span>)
- awesome-go-cn - jsonapi-errors - JSON API errors 的 Go 语言接口. (实用工具 / 高级控制台界面)
- awesome-go-with-stars - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Search and Analytic Databases)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Advanced Console UIs)
- repo-1316-awesome-go-cn - jsonapi-errors - errors) [![godoc][D]](https://godoc.org/github.com/AmuzaTkts/jsonapi-errors) (JSON / 检索及分析资料库)
- repo-1211-awesome-go-cn - jsonapi-errors - errors) [![godoc][D]](https://godoc.org/github.com/AmuzaTkts/jsonapi-errors) (JSON / 检索及分析资料库)
- awesome-Char - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Advanced Console UIs)
- awesome-reader - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Advanced Console UIs)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Advanced Console UIs)
- Go-awesome - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Search and Analytic Databases)
- awesome-go-cn - jsonapi-errors
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (Utilities / Advanced Console UIs)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (Utilities / Advanced Console UIs)
- awesome-go-cn - jsonapi-errors - errors) [![godoc][D]](https://godoc.org/github.com/AmuzaTkts/jsonapi-errors) (JSON / 检索及分析资料库)
- awesome-go - jsonapi-errors - JSON API errors 的 Go 語言接口. (實用工具 / 高級控制台界面)
- awesome-go-handwritten - jsonapi-errors - Go bindings based on the JSON API errors reference. (Utilities / HTTP Clients)
- awesome-go2 - jsonapi-errors - Go bindings based on the JSON API errors reference. (Utilities / Advanced Console UIs)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Advanced Console UIs)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. - :arrow_down:0 - :star:0 (JSON / Advanced Console UIs)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Search and Analytic Databases)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (Utilities / Advanced Console UIs)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Advanced Console UIs)
- awesome-go-cn - jsonapi-errors
- awesome-go-zh - jsonapi-errors - errors) [![godoc][D]](https://godoc.org/github.com/AmuzaTkts/jsonapi-errors) (JSON / 检索及分析资料库)
- awesome-go-cn - jsonapi-errors
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Search and Analytic Databases)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference. (JSON / Search and Analytic Databases)
- awesome-go - jsonapi-errors - Go bindings based on the JSON API errors reference - ★ 4 (Utilities)
- go-awesome-cn-star - jsonapi-errors
README
# jsonapi-errors [![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](http://godoc.org/github.com/AmuzaTkts/jsonapi-errors) [![Build Status](https://travis-ci.org/AmuzaTkts/jsonapi-errors.svg?branch=master)](https://travis-ci.org/AmuzaTkts/jsonapi-errors) [![Coverage Status](https://coveralls.io/repos/github/AmuzaTkts/jsonapi-errors/badge.svg?branch=master)](https://coveralls.io/github/AmuzaTkts/jsonapi-errors?branch=master) [![Go ReportCard](https://goreportcard.com/badge/github.com/AmuzaTkts/jsonapi-errors)](https://goreportcard.com/report/github.com/AmuzaTkts/jsonapi-errors)
This package provides error bindings based on the [JSON API](http://jsonapi.org/format/#errors)
reference.The package provides two main structs that you can use on your application, the
`Error` and `Bag` structs. When returning errors from your API you should return
a `Bag` containing one or more errors.```Go
bag := NewBagWithError(502, "Oops =(")
jsonStr, _ := json.Marshal(bag)
```The above code will return the following JSON structure:
```JSON
{
"errors": [
{
"detail": "Oops =(",
"status": "502"
}
],
"status": "502"
}
```## Multiple errors
This package adds the possibility to add multiple errors with different status
codes. The package will check for the range of the errors and will set the main
status key to the lower bound of the error class.Eg: If add an error `501` and `502`, the main status key will be `500`.
```Go
bag := NewBag()
bag.AddError(501, "Server Error 1")
bag.AddError(502, "Server Error 2")jsonStr, _ := json.Marshal(bag)
```Will return:
```JSON
{
"errors": [
{
"detail": "Server Error 1",
"status": "501"
},
{
"detail": "Server Error 2",
"status": "502"
}
],
"status": "500"
}
```It's also possible to have errors of different classes(`400` and `500` for example),
in this case the package will silently return `400` as the main status.```Go
bag := NewBag()
bag.AddError(401, "Client Error 1")
bag.AddError(502, "Server Error 1")jsonStr, _ := json.Marshal(bag)
``````JSON
{
"errors": [
{
"detail": "Client Error 1",
"status": "401"
},
{
"detail": "Server Error 1",
"status": "502"
}
],
"status": "400"
}
```