Skip to content

Commit

Permalink
feat: Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdavis3 committed May 25, 2022
1 parent 713567d commit 61c2a25
Show file tree
Hide file tree
Showing 4 changed files with 735 additions and 0 deletions.
171 changes: 171 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<!-- gomarkdoc:embed:start -->

<!-- Code generated by gomarkdoc. DO NOT EDIT -->

# problems

```go
import "github.com/tjdavis3/problems"
```

The problems package represents RFC7807 problem details\.

<details><summary>Example</summary>
<p>

Basic example

```go
{
prob := New(500, "An Error has occurred")
prob.Set("Title", "Test Error")
prob.Set("Instance", "/error/test")
prob.PrettyPrint()

}
```

#### Output

```
{
"detail": "An Error has occurred",
"instance": "/error/test",
"status": 500,
"title": "Test Error",
"type": "about:blank"
}
```

</p>
</details>

<details><summary>Example (Array)</summary>
<p>

Example with extended attributes\, including an array of problem fields\. The type must be set to something other than about:blank to add extended attributes

```go
{
prob := New(500, "An Error has occurred")
prob.Set("Title", "Test Error")
prob.Set("Instance", "/error/test")
prob.Set("Type", "uri:example:extended")
prob.Set("TraceID", "12345-67890")
issues := make(map[string]interface{})
issues["field"] = "state"
issues["message"] = "A valid state must be provided"
prob.Set("invalid-params", []map[string]interface{}{issues})
prob.PrettyPrint()

}
```

#### Output

```
{
"detail": "An Error has occurred",
"instance": "/error/test",
"invalid-params": [
{
"field": "state",
"message": "A valid state must be provided"
}
],
"status": 500,
"title": "Test Error",
"traceid": "12345-67890",
"type": "uri:example:extended"
}
```

</p>
</details>

<details><summary>Example (Extended)</summary>
<p>

Example with extended attributes\. The type must be set to something other than about:blank to add extended attributes

```go
{
prob := New(500, "An Error has occurred")
prob.Set("Title", "Test Error")
prob.Set("Instance", "/error/test")
prob.Set("Type", "uri:example:extended")
prob.Set("TraceID", "12345-67890")
prob.PrettyPrint()

}
```

#### Output

```
{
"detail": "An Error has occurred",
"instance": "/error/test",
"status": 500,
"title": "Test Error",
"traceid": "12345-67890",
"type": "uri:example:extended"
}
```

</p>
</details>

## Index

## Constants

```go
const (
// ProblemMediaType is the default media type for a Problem response
ProblemMediaType = "application/problem+json"
)
```

## type Problem

Problem is an RFC7807 representation of an error

```go
type Problem struct {
// Type is a URI reference [RFC3986] that identifies the
// problem type. This specification encourages that, when
// dereferenced, it provide human-readable documentation for the
// problem type (e.g., using HTML [W3C.REC-html5-20141028]). When
// this member is not present, its value is assumed to be
// "about:blank".
Type string `json:"type,omitempty"`
// Title is a short, human-readable summary of the problem
// type. It SHOULD NOT change from occurrence to occurrence of the
// problem, except for purposes of localization (e.g., using
// proactive content negotiation; see [RFC7231], Section 3.4).
Title string
// Status is the HTTP status code ([RFC7231], Section 6)
// generated by the origin server for this occurrence of the problem.
Status int
// Detail is a human-readable explanation specific to this
// occurrence of the problem.
Detail string
// Instance is a URI reference that identifies the specific
// occurrence of the problem. It may or may not yield further
// information if dereferenced.
Instance string `json:"instance,omitempty"`
// Attributes are extra fields/data that can be added to the problem.
// They should be set with the `Set` method. The `Type` MUST be set
// and cannot be `about:blank`
Attributes map[string]interface{} `json:"vars,omitempty" xml:"vars,omitempty"`
// contains filtered or unexported fields
}
```



Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)


<!-- gomarkdoc:embed:end -->
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/tjdavis3/problems

go 1.16
Loading

0 comments on commit 61c2a25

Please sign in to comment.