Files
moby/client/config_create.go
Sebastiaan van Stijn b20c3db932 client: request: use consistent order or arguments
Make `body` the last argument, so that requests can be inlined on call-sites.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-08-29 14:14:26 +02:00

35 lines
826 B
Go

package client
import (
"context"
"encoding/json"
"github.com/moby/moby/api/types/swarm"
)
// ConfigCreateOptions holds options for creating a config.
type ConfigCreateOptions struct {
Spec swarm.ConfigSpec
}
// ConfigCreateResult holds the result from the ConfigCreate method.
type ConfigCreateResult struct {
ID string
}
// ConfigCreate creates a new config.
func (cli *Client) ConfigCreate(ctx context.Context, options ConfigCreateOptions) (ConfigCreateResult, error) {
resp, err := cli.post(ctx, "/configs/create", nil, nil, options.Spec)
defer ensureReaderClosed(resp)
if err != nil {
return ConfigCreateResult{}, err
}
var out swarm.ConfigCreateResponse
err = json.NewDecoder(resp.Body).Decode(&out)
if err != nil {
return ConfigCreateResult{}, err
}
return ConfigCreateResult{ID: out.ID}, nil
}