Skip to content

Commit 005287f

Browse files
feat: Add support for YAML parsing
1 parent 0d4a717 commit 005287f

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

errhandler.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package errhandler
33
import (
44
"encoding/json"
55
"net/http"
6+
7+
"go.yaml.in/yaml/v4"
68
)
79

810
// Wrap an http.HandlerFunc, allowing for errors to be handled in a more
@@ -43,3 +45,8 @@ func SendString(w http.ResponseWriter, message string) error {
4345
func ParseJSON(r *http.Request, val any) error {
4446
return json.NewDecoder(r.Body).Decode(val)
4547
}
48+
49+
// ParseYAML can be used to parse a string from the body of a request.
50+
func ParseYAML(r *http.Request, val any) error {
51+
return yaml.NewDecoder(r.Body).Decode(val)
52+
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module github.com/codingconcepts/errhandler
22

33
go 1.22.4
4+
5+
require go.yaml.in/yaml/v4 v4.0.0-rc.4

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
go.yaml.in/yaml/v4 v4.0.0-rc.4 h1:UP4+v6fFrBIb1l934bDl//mmnoIZEDK0idg1+AIvX5U=
2+
go.yaml.in/yaml/v4 v4.0.0-rc.4/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=

0 commit comments

Comments
 (0)