From 87d772a7d708fec12f48cd8adc0dedff6e1025da Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 26 Aug 2024 10:15:20 +0200 Subject: Adding upstream version 1.47.0. Signed-off-by: Daniel Baumann --- .../go.d.plugin/modules/phpdaemon/client.go | 77 ---------------------- 1 file changed, 77 deletions(-) delete mode 100644 src/go/collectors/go.d.plugin/modules/phpdaemon/client.go (limited to 'src/go/collectors/go.d.plugin/modules/phpdaemon/client.go') diff --git a/src/go/collectors/go.d.plugin/modules/phpdaemon/client.go b/src/go/collectors/go.d.plugin/modules/phpdaemon/client.go deleted file mode 100644 index e860ec408..000000000 --- a/src/go/collectors/go.d.plugin/modules/phpdaemon/client.go +++ /dev/null @@ -1,77 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later - -package phpdaemon - -import ( - "encoding/json" - "fmt" - "io" - "net/http" - - "github.com/netdata/netdata/go/go.d.plugin/pkg/web" -) - -type decodeFunc func(dst interface{}, reader io.Reader) error - -func decodeJson(dst interface{}, reader io.Reader) error { return json.NewDecoder(reader).Decode(dst) } - -func newAPIClient(httpClient *http.Client, request web.Request) *client { - return &client{ - httpClient: httpClient, - request: request, - } -} - -type client struct { - httpClient *http.Client - request web.Request -} - -func (c *client) queryFullStatus() (*FullStatus, error) { - var status FullStatus - err := c.doWithDecode(&status, decodeJson, c.request) - if err != nil { - return nil, err - } - - return &status, nil -} - -func (c *client) doWithDecode(dst interface{}, decode decodeFunc, request web.Request) error { - req, err := web.NewHTTPRequest(request) - if err != nil { - return fmt.Errorf("error on creating http request to %s : %v", request.URL, err) - } - - resp, err := c.doOK(req) - defer closeBody(resp) - if err != nil { - return err - } - - if err = decode(dst, resp.Body); err != nil { - return fmt.Errorf("error on parsing response from %s : %v", req.URL, err) - } - - return nil -} - -func (c *client) doOK(req *http.Request) (*http.Response, error) { - resp, err := c.httpClient.Do(req) - if err != nil { - return resp, fmt.Errorf("error on request : %v", err) - } - - if resp.StatusCode != http.StatusOK { - return resp, fmt.Errorf("%s returned HTTP status %d", req.URL, resp.StatusCode) - } - - return resp, err -} - -func closeBody(resp *http.Response) { - if resp != nil && resp.Body != nil { - _, _ = io.Copy(io.Discard, resp.Body) - _ = resp.Body.Close() - } -} -- cgit v1.2.3