s3client

package module
v0.0.0-...-4be48cd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2026 License: MPL-2.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

S3 sdk.

AWS

MinIOSDK

RustFS

go get github.com/mkchar/s3client
	obj, err := s3client.New(s3client.Config{
		Endpoint:        "http://localhost:9000",
		AccessKeyID:     "UWCusA1LSEtaP5ZNRqQm",
		SecretAccessKey: "lG7qaSXe6DjVQJ3yUI9WmwLfAikBsTd18oxZHKYc",
		// Region:          "us-east-1",
	})
	if err != nil {
		fmt.Println(err)
	}
    bucketName := "Demo" 
	ctx := context.Background()
	err = obj.CreateBucket(ctx,bucketName)
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println("上传文件...")
	file, err := os.Open("./credentials.json")
	if err != nil {
		log.Fatalf("打开文件失败: %v", err)
	}
	defer file.Close()

	key := "uploads/example.txt" // rustfs 中的对象路径
	if err := obj.PutObject(ctx, bucketName, key, file, "text/json"); err != nil {
		log.Fatalf("上传失败: %v", err)
	}
	fmt.Printf("文件上传成功: %s/%s\n", bucketName, key)

	fmt.Println("验证文件...")
	downloaded, err := obj.GetObjectBytes(ctx, bucketName, key)
	if err != nil {
		log.Fatalf("下载验证失败: %v", err)
	}
	fmt.Printf("下载验证: %d 字节\n", len(downloaded))

=	fmt.Println("列出 Bucket 内容...")
	objects, err := obj.ListObjects(ctx, bucketName, "uploads/")
	if err != nil {
		log.Fatalf("列出失败: %v", err)
	}
	for _, obj := range objects {
		fmt.Println("  -", obj)
	}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(cfg Config) (*Client, error)

func (*Client) BucketExists

func (c *Client) BucketExists(ctx context.Context, name string) (bool, error)

func (*Client) CopyObject

func (c *Client) CopyObject(ctx context.Context, srcBucket, srcKey, dstBucket, dstKey string) error

func (*Client) CreateBucket

func (c *Client) CreateBucket(ctx context.Context, name string) error

func (*Client) DeleteBucket

func (c *Client) DeleteBucket(ctx context.Context, name string) error

func (*Client) DeleteObject

func (c *Client) DeleteObject(ctx context.Context, bucket, key string) error

func (*Client) DeleteObjects

func (c *Client) DeleteObjects(ctx context.Context, bucket string, keys []string) error

func (*Client) DownloadFile

func (c *Client) DownloadFile(ctx context.Context, bucket, key, localPath string) error

func (*Client) EmptyBucket

func (c *Client) EmptyBucket(ctx context.Context, bucket string) error

func (*Client) GetObject

func (c *Client) GetObject(ctx context.Context, bucket, key string) (io.ReadCloser, error)

func (*Client) GetObjectBytes

func (c *Client) GetObjectBytes(ctx context.Context, bucket, key string) ([]byte, error)

func (*Client) ListBuckets

func (c *Client) ListBuckets(ctx context.Context) ([]string, error)

func (*Client) ListObjects

func (c *Client) ListObjects(ctx context.Context, bucket, prefix string) ([]string, error)

func (*Client) MoveObject

func (c *Client) MoveObject(ctx context.Context, bucket, srcKey, dstKey string) error

func (*Client) ObjectExists

func (c *Client) ObjectExists(ctx context.Context, bucket, key string) (bool, error)

func (*Client) PresignGetObject

func (c *Client) PresignGetObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)

func (*Client) PresignPutObject

func (c *Client) PresignPutObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)

func (*Client) PutObject

func (c *Client) PutObject(ctx context.Context, bucket, key string, body io.Reader, contentType string) error

func (*Client) PutObjectBytes

func (c *Client) PutObjectBytes(ctx context.Context, bucket, key string, data []byte, contentType string) error

func (*Client) UploadFile

func (c *Client) UploadFile(ctx context.Context, bucket, key, localPath string) error

func (*Client) WaitBucketExists

func (c *Client) WaitBucketExists(ctx context.Context, name string, timeout time.Duration) error

type Config

type Config struct {
	Endpoint        string
	AccessKeyID     string
	SecretAccessKey string
	Region          string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址