Files
Jhon Honce 1dc6d14735 Fix file descriptor leaks and add test
* Add response.Body.Close() where needed to release HTTP
  connections to API server.
* Add tests to ensure no general leaks occur. 100% coverage would be
  required to ensure no leaks on any call.
* Update code comments to be godoc correct

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2021-08-24 16:36:10 -07:00

37 lines
919 B
Go

package containers
import (
"context"
"net/http"
"strings"
"github.com/containers/podman/v3/pkg/bindings"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/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(stringReader, http.MethodPost, "/containers/create", nil, nil)
if err != nil {
return ccr, err
}
defer response.Body.Close()
return ccr, response.Process(&ccr)
}