Skip to content

junkd0g/neji

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

neji

Package junkd0g/neji is a simple JSON error response library.

Installing

go get -u github.com/junkd0g/neji

Running the tests

go test ./...

Example

package main

import (
	"errors"
	"net/http"

	"github.com/gorilla/mux"
	nerror "github.com/junkd0g/neji"
)

func HelloWorld(w http.ResponseWriter, r *http.Request) {
	err := errors.New("This is the best error message ever")
	errorResponse, _ := nerror.SimpeErrorResponseWithStatus(500, err)

	w.Header().Set("Content-Type", "application/json")

	w.Write([]byte(errorResponse))
}

func main() {

	router := mux.NewRouter().StrictSlash(true)
	router.HandleFunc("/", HelloWorld)

	http.ListenAndServe(":8076", router)
}
nerror.SimpeErrorResponseWithStatus(500, err)

/*
	will return this response

	{
		"message" : "Your json is wrong or something",
		"status" : 500
	}
*/

nerror.SimpeErrorResponseWithStatusV2(500, err)

/*
	will return this response

	{
		"error" : {
			"status" : 502,
			"message" : "Bad gateway."
  		}
	}
*/

Authors

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages