Files
moby/client/config_create.go
Paweł Gronowski f4b06e66e1 client/config: Wrap results and options
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-10-20 22:29:36 +02:00

35 lines
830 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 {
Config 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, options.Config, nil)
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
}