{"id":30690234,"url":"https://github.com/followtheprocess/problem","last_synced_at":"2026-05-17T00:46:54.409Z","repository":{"id":311350201,"uuid":"1043108104","full_name":"FollowTheProcess/problem","owner":"FollowTheProcess","description":"RFC-7807 Problem JSON structure in Go","archived":false,"fork":false,"pushed_at":"2025-08-24T09:23:20.000Z","size":114,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-24T09:39:45.124Z","etag":null,"topics":["api","go","http","json","rfc-7807"],"latest_commit_sha":null,"homepage":"https://datatracker.ietf.org/doc/html/rfc7807","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FollowTheProcess.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-23T06:42:58.000Z","updated_at":"2025-08-24T09:00:26.000Z","dependencies_parsed_at":"2025-08-24T09:59:10.811Z","dependency_job_id":"7981e62b-900a-478d-a5b8-8180a201739a","html_url":"https://github.com/FollowTheProcess/problem","commit_stats":null,"previous_names":["followtheprocess/problem"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/FollowTheProcess/problem","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FollowTheProcess%2Fproblem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FollowTheProcess%2Fproblem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FollowTheProcess%2Fproblem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FollowTheProcess%2Fproblem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FollowTheProcess","download_url":"https://codeload.github.com/FollowTheProcess/problem/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FollowTheProcess%2Fproblem/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273218437,"owners_count":25065915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","go","http","json","rfc-7807"],"created_at":"2025-09-02T02:10:18.064Z","updated_at":"2026-05-17T00:46:54.402Z","avatar_url":"https://github.com/FollowTheProcess.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# problem\n\n[![License](https://img.shields.io/github/license/FollowTheProcess/problem)](https://github.com/FollowTheProcess/problem)\n[![Go Reference](https://pkg.go.dev/badge/go.followtheprocess.codes/problem.svg)](https://pkg.go.dev/go.followtheprocess.codes/problem)\n[![Go Report Card](https://goreportcard.com/badge/github.com/FollowTheProcess/problem)](https://goreportcard.com/report/github.com/FollowTheProcess/problem)\n[![GitHub](https://img.shields.io/github/v/release/FollowTheProcess/problem?logo=github\u0026sort=semver)](https://github.com/FollowTheProcess/problem)\n[![CI](https://github.com/FollowTheProcess/problem/workflows/CI/badge.svg)](https://github.com/FollowTheProcess/problem/actions?query=workflow%3ACI)\n[![codecov](https://codecov.io/gh/FollowTheProcess/problem/branch/main/graph/badge.svg)](https://codecov.io/gh/FollowTheProcess/problem)\n\n[RFC-7807] Problem JSON structure in Go\n\n## Project Description\n\n`problem` is a single source of truth for an [RFC-7807] `application/problem+json` structure, use it whenever you need to return an error from a REST API and your\nAPIs will all be consistent 👌🏻\n\n## Installation\n\n\u003e [!WARNING]\n\u003e This module requires the Go 1.25 jsonv2 experiment: `GOEXPERIMENT=jsonv2` in order to inline the `Extra` map when serializing\n\u003e See \u003chttps://go.dev/blog/jsonv2-exp#experimenting-with-jsonv2\u003e\n\n```shell\ngo get go.followtheprocess.codes/problem@latest\n```\n\n## Quickstart\n\nWhenever you need a problem:\n\n```go\nprob := problem.Problem{\n    Type:     \"https://example.com/probs/out-of-credit\",\n    Title:    \"Not enough credit\",\n    Detail:   \"Your current balance is 30, but that costs 50\",\n    Instance: \"/account/12345/msgs/abc\",\n    Status:   http.StatusBadRequest,\n}\n```\n\nOr you can use the `New` function with a bunch of options if you like:\n\n```go\nprob := problem.New(\n    problem.Type(\"https://example.com/probs/out-of-credit\"),\n    problem.Title(\"Not enough credit\"),\n    problem.Detail(\"Your current balance is 30, but that costs 50\"),\n    problem.Instance(\"/account/12345/msgs/abc\"),\n    problem.Status(http.StatusBadRequest),\n)\n```\n\nAnd these will both serialize to the following JSON:\n\n```json\n{\n  \"type\": \"https://example.com/probs/out-of-credit\",\n  \"title\": \"Not enough credit\",\n  \"detail\": \"Your current balance is 30, but that costs 50\",\n  \"instance\": \"/account/12345/msgs/abc\",\n  \"status\": 400\n}\n```\n\n### Any Extras?\n\n[RFC-7807] allows for arbitrary additional fields in this response to convey any additional context your error might have. Using `problem` you do this with the `Extra` map:\n\n```go\nprob := problem.Problem{\n    Type:     \"https://example.com/probs/out-of-credit\",\n    Title:    \"Not enough credit\",\n    Detail:   \"Your current balance is 30, but that costs 50\",\n    Instance: \"/account/12345/msgs/abc\",\n    Status:   http.StatusBadRequest,\n    Extra: map[string]any{\n      \"balance\":  30,\n      \"accounts\": []string{\"/accounts/12345\", \"/accounts/67890\"},\n    },\n}\n```\n\nOr with the `New` pattern:\n\n```go\nprob := problem.New(\n    problem.Type(\"https://example.com/probs/out-of-credit\"),\n    problem.Title(\"Not enough credit\"),\n    problem.Detail(\"Your current balance is 30, but that costs 50\"),\n    problem.Instance(\"/account/12345/msgs/abc\"),\n    problem.Status(http.StatusBadRequest),\n    problem.Extra(\"balance\", 30),\n    problem.Extra(\"accounts\", []string{\"/accounts/12345\", \"/accounts/67890\"}),\n)\n```\n\nThese will both serialize to the following JSON:\n\n```json\n{\n  \"type\": \"https://example.com/probs/out-of-credit\",\n  \"title\": \"Not enough credit\",\n  \"detail\": \"Your current balance is 30, but that costs 50\",\n  \"instance\": \"/account/12345/msgs/abc\",\n  \"status\": 400,\n  \"balance\": 30,\n  \"accounts\": [\n    \"/accounts/12345\",\n    \"/accounts/67890\"\n  ]\n}\n```\n\n\u003e [!TIP]\n\u003e There is also an `ExtraMap` to allow adding a whole map of extra variables in one go rather than one at a time as shown above\n\n### In HTTP Handlers\n\nThe package also provides some helpers for use in HTTP services to quickly respond with a problem:\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\n\t\"go.followtheprocess.codes/problem\"\n)\n\nfunc Bang(w http.ResponseWriter, r *http.Request) {\n\tproblem.Respond(\n\t\tw,\n\t\tproblem.Title(\"Uh oh\"),\n\t\tproblem.Detail(\"A thing went wrong\"),\n\t\tproblem.Status(http.StatusBadRequest),\n\t)\n}\n\nfunc main() {\n\thttp.HandleFunc(\"/\", Bang)\n\thttp.ListenAndServe(\":8080\", nil)\n}\n````\n\n`Respond` will:\n\n- Set the `Status` code on the response\n- Write the `Content-Type` header as `application/problem+json`\n- Marshal the `Problem` as JSON to the `http.ResponseWriter`\n  - If that fails, a default problem is written instead\n\n### Credits\n\nThis package was created with [copier] and the [FollowTheProcess/go-template] project template.\n\n[copier]: https://copier.readthedocs.io/en/stable/\n[FollowTheProcess/go-template]: https://github.com/FollowTheProcess/go-template\n[RFC-7807]: https://datatracker.ietf.org/doc/html/rfc7807\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffollowtheprocess%2Fproblem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffollowtheprocess%2Fproblem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffollowtheprocess%2Fproblem/lists"}