Documentation
¶
Index ¶
- type Client
- func (s *Client) CopyFile(ctx context.Context, sourceKey string, destinationKey string, overwrite bool) error
- func (s *Client) DeleteFile(ctx context.Context, key string) error
- func (s *Client) DownloadFile(ctx context.Context, key string) (io.ReadCloser, string, int64, error)
- func (s *Client) GenerateUploadToken(ctx context.Context, fileName string, dir string, ...) ([3]string, error)
- func (s *Client) IsFileExists(ctx context.Context, key string) (bool, error)
- func (s *Client) MoveFile(ctx context.Context, sourceKey string, destinationKey string, overwrite bool) error
- func (s *Client) UploadFile(ctx context.Context, file io.Reader, key string) (string, error)
- func (s *Client) UploadLocalFile(ctx context.Context, file string, key string) (string, error)
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
urlhandler.Handler
// contains filtered or unexported fields
}
Client provides S3-compatible object storage operations with URL handling capabilities. It uses the MinIO client library to interact with S3 or S3-compatible services.
func NewClient ¶
NewClient creates a new S3-compatible storage client with the provided configuration. It automatically configures the public base URL if not provided and initializes the URL handler for public file access.
func (*Client) CopyFile ¶
func (s *Client) CopyFile(ctx context.Context, sourceKey string, destinationKey string, overwrite bool) error
CopyFile duplicates a file from source to destination key within the S3 bucket.
func (*Client) DeleteFile ¶
DeleteFile removes a file from the S3-compatible storage bucket.
func (*Client) DownloadFile ¶
func (s *Client) DownloadFile(ctx context.Context, key string) (io.ReadCloser, string, int64, error)
DownloadFile retrieves a file from S3-compatible storage. Returns the file reader, content type, and content size.
func (*Client) GenerateUploadToken ¶
func (s *Client) GenerateUploadToken(ctx context.Context, fileName string, dir string, nameBuilder func(filename string, dir ...string) string) ([3]string, error)
GenerateUploadToken creates a presigned PUT URL for direct client uploads to S3. It generates a unique key based on the filename hash and returns the presigned URL, storage key, and public access URL. The presigned URL expires after 1 hour.
func (*Client) IsFileExists ¶
IsFileExists checks whether a file exists in the S3-compatible storage bucket.
func (*Client) MoveFile ¶
func (s *Client) MoveFile(ctx context.Context, sourceKey string, destinationKey string, overwrite bool) error
MoveFile relocates a file from source to destination key within the S3 bucket. It performs a copy operation followed by deletion of the source file.
func (*Client) UploadFile ¶
UploadFile uploads data from a reader to S3-compatible storage with the specified key.
type Config ¶
type Config struct {
Endpoint string `json:"endpoint"`
AccessKeyID string `json:"access_key"`
SecretAccessKey string `json:"secret"`
Token string `json:"token"`
Bucket string `json:"bucket"`
UseSSL bool `json:"use_ssl"`
PublicBase string `json:"public_base"`
}
Config holds the configuration parameters for S3-compatible object storage.