mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00

Automated for .go files via gomove [1]: `gomove github.com/containers/podman/v3 github.com/containers/podman/v4` Remaining files via vgrep [2]: `vgrep github.com/containers/podman/v3` [1] https://github.com/KSubedi/gomove [2] https://github.com/vrothberg/vgrep Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
37 lines
924 B
Go
37 lines
924 B
Go
package containers
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/containers/podman/v4/pkg/bindings"
|
|
"github.com/containers/podman/v4/pkg/domain/entities"
|
|
"github.com/containers/podman/v4/pkg/specgen"
|
|
jsoniter "github.com/json-iterator/go"
|
|
)
|
|
|
|
func CreateWithSpec(ctx context.Context, s *specgen.SpecGenerator, options *CreateOptions) (entities.ContainerCreateResponse, error) {
|
|
var ccr entities.ContainerCreateResponse
|
|
if options == nil {
|
|
options = new(CreateOptions)
|
|
}
|
|
_ = options
|
|
conn, err := bindings.GetClient(ctx)
|
|
if err != nil {
|
|
return ccr, err
|
|
}
|
|
specgenString, err := jsoniter.MarshalToString(s)
|
|
if err != nil {
|
|
return ccr, err
|
|
}
|
|
stringReader := strings.NewReader(specgenString)
|
|
response, err := conn.DoRequest(ctx, stringReader, http.MethodPost, "/containers/create", nil, nil)
|
|
if err != nil {
|
|
return ccr, err
|
|
}
|
|
defer response.Body.Close()
|
|
|
|
return ccr, response.Process(&ccr)
|
|
}
|