From c0a49cb839ee00ddc39c9aeb7f9fbcfe5b0dbfc7 Mon Sep 17 00:00:00 2001
From: Oleg Kovalov <oleg@hey.com>
Date: Wed, 4 Oct 2023 09:56:27 +0200
Subject: [PATCH] Add MustMarshal

---
 jsn.go | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/jsn.go b/jsn.go
index e15eac7..cf2fdfa 100644
--- a/jsn.go
+++ b/jsn.go
@@ -44,4 +44,13 @@ func UnmarshalFrom(r io.Reader, v any) error {
 	return nil
 }
 
+// MustMarshal an object to JSON, and panics if any error occurs.
+func MustMarshal(obj any) []byte {
+	b, err := json.Marshal(obj)
+	if err != nil {
+		panic(err)
+	}
+	return b
+}
+
 var errMore = errors.New("body must contain only one JSON entity")