https://github.com/ddymko/go-jsonerror
Small package which wraps error responses to follow jsonapi.org
https://github.com/ddymko/go-jsonerror
go golang-json json-api json-error jsonapi-spec
Last synced: 8 months ago
JSON representation
Small package which wraps error responses to follow jsonapi.org
- Host: GitHub
- URL: https://github.com/ddymko/go-jsonerror
- Owner: ddymko
- License: mit
- Created: 2018-10-18T15:03:45.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-09T11:56:05.000Z (about 6 years ago)
- Last Synced: 2025-04-10T07:55:37.413Z (8 months ago)
- Topics: go, golang-json, json-api, json-error, jsonapi-spec
- Language: Go
- Size: 17.6 KB
- Stars: 16
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go-extra - go-jsonerror - 10-18T15:03:45Z|2019-10-09T11:56:05Z| (JSON / Advanced Console UIs)
- awesome-go-cn - go-jsonerror - JsonError is meant to allow us to easily create json response errors that follow the JsonApi spec. [![近三年未更新][Y]](https://github.com/ddymko/go-jsonerror) [![godoc][D]](https://godoc.org/github.com/ddymko/go-jsonerror) (JSON / 检索及分析资料库)
- awesome-go-with-stars - go-jsonerror - Go-JsonError is meant to allow us to easily create json response errors that follow the JsonApi spec. (JSON / Search and Analytic Databases)
- awesome-Char - go-jsonerror - Go-JsonError is ment to allow us to easily create json response errors that follow the JsonApi spec. (JSON / Advanced Console UIs)
- awesome-go-plus - go-jsonerror - Go-JsonError is meant to allow us to easily create json response errors that follow the JsonApi spec.  (JSON / Search and Analytic Databases)
- awesome-go - go-jsonerror - Go-JsonError is meant to allow us to easily create json response errors that follow the JsonApi spec. (JSON / Search and Analytic Databases)
- fucking-awesome-go - go-jsonerror - Go-JsonError is meant to allow us to easily create json response errors that follow the JsonApi spec. (JSON / Search and Analytic Databases)
- awesome-go-cn - go-jsonerror - JsonError`的目的是让我们能够轻松创建遵循`JsonApi`规范的`json`响应错误。 (JSON / SQL 查询语句构建库)
- awesome-go - go-jsonerror - Go-JsonError is meant to allow us to easily create json response errors that follow the JsonApi spec. (JSON / Search and Analytic Databases)
- awesome-go - go-jsonerror - Go-JsonError is meant to allow us to easily create json response errors that follow the JsonApi spec. (JSON / Search and Analytic Databases)
- awesome-go - go-jsonerror - Go-JsonError is ment to allow us to easily create json response errors that follow the JsonApi spec. (JSON / Search and Analytic Databases)
- awesome-go - go-jsonerror - Go-JsonError is meant to allow us to easily create json response errors that follow the JsonApi spec. (JSON / Search and Analytic Databases)
- awesome-go-cn - go-jsonerror - JsonError is meant to allow us to easily create json response errors that follow the JsonApi spec. [![近三年未更新][Y]](https://github.com/ddymko/go-jsonerror) [![godoc][D]](https://godoc.org/github.com/ddymko/go-jsonerror) (JSON / 检索及分析资料库)
- awesome-go - go-jsonerror - Go-JsonError is ment to allow us to easily create json response errors that follow the JsonApi spec. (JSON / Advanced Console UIs)
README
# Go-JsonError
[](https://goreportcard.com/report/github.com/ddymko/go-jsonerror) [](https://travis-ci.org/ddymko/go-jsonerror) [](https://codecov.io/github/ddymko/go-jsonerror?branch=master)
[](https://godoc.org/github.com/ddymko/go-jsonerror)
[](https://github.com/avelino/awesome-go)
Go-JsonError is meant to allow us to easily create json response errors that follow the JsonApi spec.
[Json API Spec](https://jsonapi.org/format/#errors)
## Usuage
In order to use jsonError you will need to initliaze the ErrorJson struct. Then when you would like to add an error you must pass in a ErrorComp struct to the AddError().
This follows the jsonapi spec where the error response must return an array.
Here is a basic example
``` go
var err ErrorJSON
errorComposition := ErrorComp{
Detail: "this is a error message",
Code: "This is the code",
Source: Source{
Pointer: "/unit/tests",
},
Title: "Title Test",
Status: 200,
}
err.AddError(errorComposition)
err.Error()
err.ErrorByte()
```
## Running the tests
This package is just using the standard test packge included with go. You can run the test cases with
``` sh
go test ./...
```
## Contributing
Please feel free to submit any pull requests.
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/ddymko/go-jsonerror/tags).
## Authors
* **David Dymko**
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details