mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
40 lines
753 B
Go
40 lines
753 B
Go
package containerd
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/containerd/containerd/v2/client"
|
|
)
|
|
|
|
// Client is a containerd client for image operations.
|
|
type Client struct {
|
|
Client *client.Client
|
|
}
|
|
|
|
// NewClient creates a new containerd client connected to the given socket path.
|
|
func NewClient(sockPath string) (*Client, error) {
|
|
if sockPath == "" {
|
|
return nil, fmt.Errorf("containerd socket path is required")
|
|
}
|
|
|
|
c, err := client.New(
|
|
sockPath,
|
|
client.WithDefaultNamespace("moby"),
|
|
client.WithTimeout(60*time.Second),
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Client{Client: c}, nil
|
|
}
|
|
|
|
// Close closes the containerd client connection.
|
|
func (c *Client) Close() error {
|
|
if c.Client != nil {
|
|
return c.Client.Close()
|
|
}
|
|
return nil
|
|
}
|