summaryrefslogblamecommitdiff
path: root/api/utils.go
blob: 40b41e638091243305eee5c3feb05b5fb74b9ab7 (plain) (tree)




























                                          
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
}