Skip to content
A go library that implements application/problem+json
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Initial commit Aug 2, 2019 renamed towriteer to writeto Aug 7, 2019
coverage_badge.png houston we have a problem! Aug 2, 2019
problem.go renamed towriteer to writeto Aug 7, 2019
problem_test.go renamed towriteer to writeto Aug 7, 2019



A golang library that implements application/problem+json



problem.New(problem.Title("Not Found"), problem.Status(404)).JSONString()

Will produce this:

  "status": 404,
  "title": "Not Found"

You can also append some more options:

p := problem.New(problem.Title("Not Found"), problem.Status(404))
p.Append(problem.Detail("some more details"))

// create json as []byte
jsonBytes := p.JSON()

Custom key/values are also supported:

problem.New(problem.Title("Not Found"), problem.Custom("key", "value"))

To write the Problem directly to a http.ResponseWriter:

http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    problem.New(problem.Type(""), problem.Status(404)).WriteTo(w)

If you are using gin you can simply reply the problem to the client:

func(c *gin.Context) {
  problem.New(problem.Title("houston! we have a problem"), problem.Status(http.StatusNotFound)).WriteTo(c.Writer)
You can’t perform that action at this time.