MCPcopy
hub / github.com/IBM/sarama / Proxy

Method Proxy

internal/toxiproxy/client.go:53–76  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

51}
52
53func (c *Client) Proxy(name string) (*Proxy, error) {
54 req, err := http.NewRequest("GET", c.endpoint+"/proxies/"+name, nil)
55 if err != nil {
56 return nil, fmt.Errorf("failed to make proxy request: %w", err)
57 }
58 resp, err := c.httpClient.Do(req) // #nosec G704 -- toxiproxy endpoint is controlled test infrastructure.
59 if err != nil {
60 return nil, fmt.Errorf("failed to http get proxy: %w", err)
61 }
62 defer resp.Body.Close()
63
64 if resp.StatusCode != 200 {
65 body, _ := io.ReadAll(resp.Body)
66 return nil, fmt.Errorf("error getting proxy %s: %s %s", name, resp.Status, body)
67 }
68
69 var p Proxy
70 if err := json.NewDecoder(resp.Body).Decode(&p); err != nil {
71 return nil, fmt.Errorf("error decoding json for proxy %s: %w", name, err)
72 }
73 p.client = c
74
75 return &p, nil
76}
77
78func (c *Client) ResetState() error {
79 req, err := http.NewRequest("POST", c.endpoint+"/reset", http.NoBody)

Callers 1

setupToxiProxiesFunction · 0.80

Implementers 2

stubLeaderClientasync_producer_test.go
clientclient.go

Calls 2

ErrorfMethod · 0.65
CloseMethod · 0.65

Tested by 1

setupToxiProxiesFunction · 0.64