mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
ensureReaderClosed was designed to be usable regardless if a response was nil (error) or non-nil (success). Some code-paths were optimized to avoid using a defer (which used to have an overhead), but the overhead of defer is neglectable in current versions of Go, and some of these optimizations made the logic more complicated (and err-prone). This patch switches to use a defer for all places. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
27 lines
572 B
Go
27 lines
572 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
"strconv"
|
|
)
|
|
|
|
// PluginEnableOptions holds parameters to enable plugins.
|
|
type PluginEnableOptions struct {
|
|
Timeout int
|
|
}
|
|
|
|
// PluginEnable enables a plugin
|
|
func (cli *Client) PluginEnable(ctx context.Context, name string, options PluginEnableOptions) error {
|
|
name, err := trimID("plugin", name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
query := url.Values{}
|
|
query.Set("timeout", strconv.Itoa(options.Timeout))
|
|
|
|
resp, err := cli.post(ctx, "/plugins/"+name+"/enable", query, nil, nil)
|
|
defer ensureReaderClosed(resp)
|
|
return err
|
|
}
|