oss_svc

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BucketItem

type BucketItem struct {
	Name         string `json:"name"`
	CreationDate int64  `json:"creationDate"`
}

BucketItem 是账号下的一个 Bucket。

type Client

type Client interface {
	ListBuckets(ctx context.Context) ([]BucketItem, error)
	// ListObjects 分页契约:maxKeys<=0 表示"使用服务端默认值";当超出 maxKeys 还有更多对象时,
	// 实现必须多返回 1 条(即最多返回 maxKeys+1 条),调用方(listObjectsWith)靠这多出的一条
	// 判断 IsTruncated 并截断结果——若实现只按字面返回恰好 maxKeys 条,截断检测会永远为 false,
	// 分页将在"假的最后一页"上卡死。
	ListObjects(ctx context.Context, bucket, prefix string, maxKeys int, startAfter string) ([]ObjectItem, error)
	StatObject(ctx context.Context, bucket, key string) (ObjectItem, error)
	RemoveObject(ctx context.Context, bucket, key string) error
	CopyObject(ctx context.Context, srcBucket, srcKey, dstBucket, dstKey string) error
	RemoveObjects(ctx context.Context, bucket string, keys []string) error
	PutObject(ctx context.Context, bucket, key string, r io.Reader, size int64, contentType string) error
	GetObject(ctx context.Context, bucket, key string) (io.ReadCloser, int64, error)
	PresignGet(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
	PresignPut(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
	BucketExists(ctx context.Context, bucket string) (bool, error)
}

Client 是服务依赖的窄对象存储接口(可 mock)。

type CopyRequest

type CopyRequest struct {
	AssetID   int64  `json:"assetId"`
	SrcBucket string `json:"srcBucket"`
	SrcKey    string `json:"srcKey"`
	DstBucket string `json:"dstBucket"`
	DstKey    string `json:"dstKey"`
}

type CreateFolderRequest

type CreateFolderRequest struct {
	AssetID int64  `json:"assetId"`
	Bucket  string `json:"bucket"`
	Prefix  string `json:"prefix"` // 服务端规范化为以 "/" 结尾
}

type ListObjectsRequest

type ListObjectsRequest struct {
	AssetID           int64  `json:"assetId"`
	Bucket            string `json:"bucket"`
	Prefix            string `json:"prefix"`
	MaxKeys           int    `json:"maxKeys"`
	ContinuationToken string `json:"continuationToken"`
}

type ListObjectsResult

type ListObjectsResult struct {
	Prefixes              []string     `json:"prefixes"`
	Objects               []ObjectItem `json:"objects"`
	NextContinuationToken string       `json:"nextContinuationToken"`
	IsTruncated           bool         `json:"isTruncated"`
}

type ObjectItem

type ObjectItem struct {
	Key          string `json:"key"`
	Size         int64  `json:"size"`
	LastModified int64  `json:"lastModified"`
	ETag         string `json:"etag"`
	StorageClass string `json:"storageClass"`
	ContentType  string `json:"contentType"`
	IsPrefix     bool   `json:"isPrefix"`
}

ObjectItem 是 Bucket 下的一个对象或"文件夹"前缀。

type ObjectRequest

type ObjectRequest struct {
	AssetID int64  `json:"assetId"`
	Bucket  string `json:"bucket"`
	Key     string `json:"key"`
}

type PresignRequest

type PresignRequest struct {
	AssetID    int64  `json:"assetId"`
	Bucket     string `json:"bucket"`
	Key        string `json:"key"`
	ExpirySecs int    `json:"expirySecs"`
}

type RemoveObjectsRequest

type RemoveObjectsRequest struct {
	AssetID int64    `json:"assetId"`
	Bucket  string   `json:"bucket"`
	Keys    []string `json:"keys"`
}

type Service

type Service struct{}

func New

func New() *Service

func (*Service) CopyObject

func (s *Service) CopyObject(ctx context.Context, req *CopyRequest) error

func (*Service) CreateFolder

func (s *Service) CreateFolder(ctx context.Context, req *CreateFolderRequest) error

func (*Service) GetObject

func (s *Service) GetObject(ctx context.Context, assetID int64, bucket, key string) (io.ReadCloser, int64, error)

GetObject 是给 app 层流式下载用的原语:connect 后返回对象流 + 总大小。

func (*Service) ListBuckets

func (s *Service) ListBuckets(ctx context.Context, assetID int64) ([]BucketItem, error)

func (*Service) ListObjects

func (s *Service) ListObjects(ctx context.Context, req *ListObjectsRequest) (*ListObjectsResult, error)

func (*Service) MoveObject

func (s *Service) MoveObject(ctx context.Context, req *CopyRequest) error

func (*Service) PresignGet

func (s *Service) PresignGet(ctx context.Context, req *PresignRequest) (string, error)

func (*Service) PresignPut

func (s *Service) PresignPut(ctx context.Context, req *PresignRequest) (string, error)

func (*Service) PutObject

func (s *Service) PutObject(ctx context.Context, assetID int64, bucket, key string, r io.Reader, size int64, contentType string) error

PutObject 是给 app 层流式上传用的原语:connect 后把(通常已包进度)reader 写入对象。

func (*Service) RemoveObject

func (s *Service) RemoveObject(ctx context.Context, req *ObjectRequest) error

func (*Service) RemoveObjects

func (s *Service) RemoveObjects(ctx context.Context, req *RemoveObjectsRequest) error

func (*Service) StatObject

func (s *Service) StatObject(ctx context.Context, req *ObjectRequest) (*ObjectItem, error)

func (*Service) TestConfig

func (s *Service) TestConfig(ctx context.Context, cfg *asset_entity.OSSConfig, secret string) error

TestConfig 验证一份未保存的配置(表单"测试连接")。

func (*Service) TestConnection

func (s *Service) TestConnection(ctx context.Context, assetID int64) error

TestConnection 用已保存的资产拨号并列 Bucket 以验证凭证。

Directories

Path Synopsis
Package mock_ossclient is a generated GoMock package.
Package mock_ossclient is a generated GoMock package.

Jump to

Keyboard shortcuts

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