objstorage

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package objstorage 提供对象存储相关封装,目前接入的是蓝盾制品库(bkrepo) 如果 SaaS 开发者需要使用其他云对象存储(如 COS,S3, Ceph 等),可参考相关实现

Index

Constants

View Source
const (
	// ObjectAlreadyExistsErrorCode 对象已存在错误码
	ObjectAlreadyExistsErrorCode = 250107
	// DirAlreadyExistsErrorCode 目录已存在
	DirAlreadyExistsErrorCode = 251012
)

Variables

This section is empty.

Functions

func IsBkRepoAvailable

func IsBkRepoAvailable() bool

IsBkRepoAvailable 判断蓝盾制品仓库是否可用

Types

type BkGenericRepoClient

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

BkGenericRepoClient 蓝盾通用制品仓库客户端

func NewClient

func NewClient(ctx context.Context) *BkGenericRepoClient

NewClient 获取对象存储客户端

func (*BkGenericRepoClient) CreateDir

func (c *BkGenericRepoClient) CreateDir(ctx context.Context, path string) error

CreateDir 在制品库中创建目录(path)

func (*BkGenericRepoClient) DeleteDir

func (c *BkGenericRepoClient) DeleteDir(ctx context.Context, path string) error

DeleteDir 删除制品库中的目录(path)

func (*BkGenericRepoClient) DeleteFile

func (c *BkGenericRepoClient) DeleteFile(ctx context.Context, path string) error

DeleteFile 删除文件

func (*BkGenericRepoClient) DownloadFile

func (c *BkGenericRepoClient) DownloadFile(ctx context.Context, path string) (io.ReadCloser, error)

DownloadFile 下载文件

func (*BkGenericRepoClient) GenPreSignedUrl

func (c *BkGenericRepoClient) GenPreSignedUrl(
	ctx context.Context, path string, expireSeconds int,
) (*PreSignedUrlData, error)

GenPreSignedUrl 生成预签名 URL(只允许下载)

func (*BkGenericRepoClient) GetFileMetadata

func (c *BkGenericRepoClient) GetFileMetadata(ctx context.Context, path string) (map[string]string, error)

GetFileMetadata 获取文件元数据

func (*BkGenericRepoClient) ListDir

func (c *BkGenericRepoClient) ListDir(ctx context.Context, path string, curPage, pageSize int) (*DirInfo, error)

ListDir 分页列出制品库目录(path)下的文件(path 需要是某个目录)

func (*BkGenericRepoClient) UploadFile

func (c *BkGenericRepoClient) UploadFile(ctx context.Context, file io.Reader, path string, allowOverwrite bool) error

UploadFile 上传文件 file 到制品库 path 路径上,允许通过 allowOverwrite 参数决定是否覆盖已有文件

type CreateDirResp

type CreateDirResp struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data"`
	TraceID string `json:"traceId"`
}

CreateDirResp 创建目录返回结果

type DeleteDirResp

type DeleteDirResp struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data"`
	TraceID string `json:"traceId"`
}

DeleteDirResp 删除目录返回结果

type DirInfo

type DirInfo struct {
	PageNumber int      `json:"pageNumber"`
	PageSize   int      `json:"pageSize"`
	TotalPages int64    `json:"totalPages"`
	Total      int64    `json:"totalRecords"`
	Objects    []Object `json:"records"`
}

DirInfo 蓝盾制品库目录文件数据

type GenPreSignedUrlResp

type GenPreSignedUrlResp struct {
	Code    int                `json:"code"`
	Message string             `json:"message"`
	Data    []PreSignedUrlData `json:"data"`
	TraceID string             `json:"traceId"`
}

GenPreSignedUrlResp 生成预签名 URL(只允许下载)返回结果

type ListDirResp

type ListDirResp struct {
	Code    int     `json:"code"`
	Message string  `json:"message"`
	Data    DirInfo `json:"data"`
	TraceID string  `json:"traceId"`
}

ListDirResp 分页查询蓝盾制品库目录下文件返回结果

type Object

type Object struct {
	Path             string            `json:"path"`
	Name             string            `json:"name"`
	FullPath         string            `json:"fullPath"`
	IsDir            bool              `json:"folder"`
	Size             int64             `json:"size"`
	SHA256           string            `json:"sha256,omitempty"`
	MD5              string            `json:"md5,omitempty"`
	Metadata         map[string]string `json:"metadata,omitempty"`
	CreatedBy        string            `json:"createdBy,omitempty"`
	CreatedDate      string            `json:"createdDate,omitempty"`
	LastModifiedBy   string            `json:"lastModifiedBy,omitempty"`
	LastModifiedDate string            `json:"lastModifiedDate,omitempty"`
}

Object 蓝盾制品库文件数据

type PreSignedUrlData

type PreSignedUrlData struct {
	FullPath   string `json:"fullPath"`
	Url        string `json:"url"`
	ExpireDate string `json:"expireDate"`
}

PreSignedUrlData 预签名 URL 数据

type UploadFileResp

type UploadFileResp struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    Object `json:"data"`
	TraceID string `json:"traceId"`
}

UploadFileResp 上传文件返回结果

Jump to

Keyboard shortcuts

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