jsonerror

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: MIT Imports: 1 Imported by: 0

README

Go-JsonError

Go Report Card Build Status Coveragestatus GoDoc Mentioned in Awesome Go

Go-JsonError is ment to allow us to easily create json response errors that follow the JsonApi spec.

Json API Spec

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

	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.ByteError()

Running the tests

This package is just using the standard test packge included with go. You can run the test cases with

go test ./...

Contributing

Please feel free to submit any pull requests.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • David Dymko

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorComp

type ErrorComp struct {
	ID     string `json:"id,omitempty"`
	Status int    `json:"status,omitempty"`
	Code   string `json:"code,omitempty"`
	Title  string `json:"title,omitempty"`
	Detail string `json:"detail,omitempty"`
	Source Source `json:"source,omitempty"`
}

ErrorComp is a error structure that follows the json spec.

type ErrorJSON

type ErrorJSON struct {
	Errors []ErrorComp `json:"errors"`
}

ErrorJSON contains an array of Errors.

func (*ErrorJSON) AddError

func (e *ErrorJSON) AddError(comp ErrorComp)

AddError allows adding fields to the error

func (*ErrorJSON) Error

func (e *ErrorJSON) Error() string

Error returns the error in string format

func (*ErrorJSON) ErrorByte

func (e *ErrorJSON) ErrorByte() []byte

ErrorByte returns the error in an []byte

type Source

type Source struct {
	Pointer string `json:"pointer,omitempty"`
}

Source is represents

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL