|
|
@ -92,8 +92,12 @@ func (c *Client) UpdateResource(ctx context.Context, link ResourceLink, update R |
|
|
|
return c.put(ctx, link.Path(), update, nil) |
|
|
|
} |
|
|
|
|
|
|
|
func (c *Client) LegacyDiscover(ctx context.Context, kind string) error { |
|
|
|
return c.legacyPost(ctx, kind, nil, nil) |
|
|
|
} |
|
|
|
|
|
|
|
func (c *Client) SSE(ctx context.Context) <-chan SSEUpdate { |
|
|
|
ch := make(chan SSEUpdate, 4)0 |
|
|
|
ch := make(chan SSEUpdate, 4) |
|
|
|
go func() { |
|
|
|
defer close(ch) |
|
|
|
|
|
|
@ -264,6 +268,43 @@ func (c *Client) post(ctx context.Context, path string, body interface{}, target |
|
|
|
return json.NewDecoder(res.Body).Decode(&target) |
|
|
|
} |
|
|
|
|
|
|
|
func (c *Client) legacyPost(ctx context.Context, resource string, body interface{}, target interface{}) error { |
|
|
|
select { |
|
|
|
case <-ctx.Done(): |
|
|
|
return ctx.Err() |
|
|
|
case <-c.ch: |
|
|
|
defer func() { |
|
|
|
c.ch <- struct{}{} |
|
|
|
}() |
|
|
|
} |
|
|
|
|
|
|
|
rb, err := reqBody(body) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
if c.token != "" { |
|
|
|
resource = c.token + "/" + resource |
|
|
|
} |
|
|
|
|
|
|
|
req, err := http.NewRequest("POST", fmt.Sprintf("http://%s/api/%s", c.host, resource), rb) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
res, err := httpClient.Do(req.WithContext(ctx)) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
defer res.Body.Close() |
|
|
|
|
|
|
|
if target == nil { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
return json.NewDecoder(res.Body).Decode(target) |
|
|
|
} |
|
|
|
|
|
|
|
func reqBody(body interface{}) (io.Reader, error) { |
|
|
|
if body == nil { |
|
|
|
return nil, nil |
|
|
|