mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-24 06:28:13 +01:00
29 lines
556 B
Go
29 lines
556 B
Go
package docker
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/containers/image/docker"
|
|
"github.com/containers/image/types"
|
|
)
|
|
|
|
func (c *RegistryClient) newImage(ctx context.Context, imageStr string) (types.ImageCloser, error) {
|
|
if !strings.HasPrefix(imageStr, "//") {
|
|
imageStr = fmt.Sprintf("//%s", imageStr)
|
|
}
|
|
|
|
ref, err := docker.ParseReference(imageStr)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("invalid image name %s: %v", imageStr, err)
|
|
}
|
|
|
|
img, err := ref.NewImage(ctx, c.sysCtx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return img, nil
|
|
}
|