diff options
Diffstat (limited to 'api/utils.go')
-rw-r--r-- | api/utils.go | 29 |
1 files changed, 29 insertions, 0 deletions
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 +} |