From 9a5ef962fa8b0a8d800a97eb331aa7b8deaf44eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sun, 30 Mar 2025 01:56:13 +0900 Subject: [PATCH] feat: customizable client --- api.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api.go b/api.go index 7f0a11a..62290ea 100644 --- a/api.go +++ b/api.go @@ -15,19 +15,28 @@ const ( type API struct { api string // api to call key string // key in Authorization: Bearer + cli *http.Client } func NewAPI(api, key string) API { return API{api: api, key: key} } +func (api *API) SetHTTPClient(c *http.Client) { + api.cli = c +} + func (api *API) Request(model Model) (string, error) { req, err := http.NewRequest("POST", model.API(api.api, api.key), model.Body()) if err != nil { return "", err } model.Header(api.key, req.Header) - resp, err := http.DefaultClient.Do(req) + cli := http.DefaultClient + if api.cli != nil { + cli = api.cli + } + resp, err := cli.Do(req) if err != nil { return "", err }