From a68800a0517ef4ae842c0780772c755910ed20f3 Mon Sep 17 00:00:00 2001 From: Gustavo Chain Date: Fri, 13 Sep 2024 09:26:59 -0300 Subject: [PATCH] allow json.Marshal overriding --- request.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/request.go b/request.go index 8e4d9ad..4a117e0 100644 --- a/request.go +++ b/request.go @@ -10,8 +10,11 @@ import ( "net/http/httputil" ) +// Marshal is a public variable that can be used to override the default JSON marshalling function. +var Marshal func(v interface{}) ([]byte, error) = json.Marshal + func postJSON(ctx context.Context, c *Client, url string, body interface{}, res interface{}) error { - buf, err := json.Marshal(body) + buf, err := Marshal(body) if err != nil { return err } @@ -30,7 +33,7 @@ func putResource(ctx context.Context, c *Client, url string, body interface{}, r body = `{}` } - buf, err := json.Marshal(body) + buf, err := Marshal(body) if err != nil { return err }