Documentation ¶
Overview ¶
Example (BucketFiles) ¶
package main import ( "context" "fmt" "github.com/aws/aws-sdk-go-v2/aws" "github.com/sqjian/go-kit/oss/s3" "os" ) var awsConfig *aws.Config func main() { checkErr := func(err error) { if err != nil { panic(err) } } cli, err := s3.NewS3Cli( s3.WithAwsConfig(awsConfig), s3.WithProgressOutput(os.Stderr), ) checkErr(err) var ( bucket = "xxx" prefixHint = "" ) { files, err := cli.BucketFiles( context.Background(), bucket, prefixHint, ) checkErr(err) fmt.Println(files) } }
Output:
Example (DeleteFile) ¶
package main import ( "context" "github.com/aws/aws-sdk-go-v2/aws" "github.com/sqjian/go-kit/oss/s3" "os" ) var awsConfig *aws.Config func main() { checkErr := func(err error) { if err != nil { panic(err) } } cli, err := s3.NewS3Cli( s3.WithAwsConfig(awsConfig), s3.WithProgressOutput(os.Stdin), ) checkErr(err) var ( bucket = "xxx" objectKey = "xxx" ) { err := cli.DeleteFile( context.Background(), bucket, objectKey, ) checkErr(err) } }
Output:
Example (DownloadFile) ¶
package main import ( "context" "fmt" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/feature/s3/manager" "github.com/sqjian/go-kit/oss/s3" "os" ) var awsConfig *aws.Config func main() { checkErr := func(err error) { if err != nil { panic(err) } } cli, err := s3.NewS3Cli( s3.WithAwsConfig(awsConfig), s3.WithProgressOutput(os.Stderr), ) checkErr(err) var ( bucket = "xxx" objectKey = "xxx" buf = manager.NewWriteAtBuffer(nil) ) { err := cli.DownloadFile( context.Background(), bucket, objectKey, buf, ) checkErr(err) fmt.Println(len(buf.Bytes())) } }
Output:
Example (UploadFile) ¶
package main import ( "bytes" "context" "github.com/aws/aws-sdk-go-v2/aws" "github.com/sqjian/go-kit/oss/s3" "os" ) var awsConfig *aws.Config func main() { checkErr := func(err error) { if err != nil { panic(err) } } cli, err := s3.NewS3Cli( s3.WithAwsConfig(awsConfig), s3.WithProgressOutput(os.Stderr), ) checkErr(err) var ( bucket = "xxx" objectKey = "xxx" data = bytes.Repeat([]byte("x"), 1024*1024*1024) ) { err := cli.UploadFile( context.Background(), bucket, objectKey, s3.NewFsFile("", data, 0644), ) checkErr(err) } }
Output:
Index ¶
- func NewAwsConfig(opts ...OptionFunc) (*aws.Config, error)
- func NewFsFile(name string, contents []byte, mode fs.FileMode) fs.File
- type BucketListChunk
- type Client
- type Err
- type FakeFile
- func (f *FakeFile) Close() error
- func (f *FakeFile) IsDir() bool
- func (f *FakeFile) ModTime() time.Time
- func (f *FakeFile) Mode() fs.FileMode
- func (f *FakeFile) Name() string
- func (f *FakeFile) Read(p []byte) (int, error)
- func (f *FakeFile) Reset() *FakeFile
- func (f *FakeFile) Size() int64
- func (f *FakeFile) Stat() (fs.FileInfo, error)
- func (f *FakeFile) Sys() any
- type OptionFunc
- type S3client
- func (c *S3client) BucketFiles(ctx context.Context, bucketName string, directoryPrefix string) ([]string, error)
- func (c *S3client) DeleteFile(ctx context.Context, bucketName string, remotePath string) error
- func (c *S3client) DownloadFile(ctx context.Context, bucketName string, remotePath string, ...) error
- func (c *S3client) UploadFile(ctx context.Context, bucketName string, remotePath string, localFile fs.File) error
- type S3clientOpt
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAwsConfig ¶
func NewAwsConfig(opts ...OptionFunc) (*aws.Config, error)
Types ¶
type BucketListChunk ¶
type Client ¶
type Client interface { BucketFiles(ctx context.Context, bucketName string, prefixHint string) ([]string, error) UploadFile(ctx context.Context, bucketName string, remotePath string, localFile fs.File) error DownloadFile(ctx context.Context, bucketName string, remotePath string, localFile io.WriterAt) error DeleteFile(ctx context.Context, bucketName string, remotePath string) error }
type FakeFile ¶
type FakeFile struct {
// contains filtered or unexported fields
}
FakeFile implements FileLike and also fs.FileInfo.
type OptionFunc ¶
type OptionFunc func(*s3Config)
func WithAccessKey ¶
func WithAccessKey(accessKey string) OptionFunc
func WithEndpoint ¶
func WithEndpoint(endpoint string) OptionFunc
func WithSecretKey ¶
func WithSecretKey(secretKey string) OptionFunc
type S3client ¶
type S3client struct {
// contains filtered or unexported fields
}
func NewS3Cli ¶
func NewS3Cli(opts ...S3clientOpt) (*S3client, error)
func (*S3client) BucketFiles ¶
func (*S3client) DeleteFile ¶
func (*S3client) DownloadFile ¶
type S3clientOpt ¶
type S3clientOpt interface {
// contains filtered or unexported methods
}
func WithAwsConfig ¶
func WithAwsConfig(awsConfig *aws.Config) S3clientOpt
func WithProgressOutput ¶
func WithProgressOutput(progressOutput io.Writer) S3clientOpt
Click to show internal directories.
Click to hide internal directories.