From 3dd390c0cb56ffb5a7c1f94afaed0b80ad12cbe1 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Wed, 13 Mar 2024 06:47:19 +0530 Subject: repo: init --- api/utils.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 api/utils.go (limited to 'api/utils.go') diff --git a/api/utils.go b/api/utils.go new file mode 100644 index 0000000..40b41e6 --- /dev/null +++ b/api/utils.go @@ -0,0 +1,29 @@ +package api + +import ( + "encoding/json" + "io" +) + +func unmarshal(r io.Reader, v any) error { + body, err := io.ReadAll(r) + if err != nil { + return err + } + + err = json.Unmarshal(body, v) + if err != nil { + return err + } + + return nil +} + +func marshal(v any) (string, error) { + b, err := json.Marshal(v) + if err != nil { + return "", err + } + + return string(b), nil +} -- cgit v1.2.3