Documentation
¶
Overview ¶
Package s3 implement abstract file storage API with Amazon Web Service s3
Index ¶
- Constants
- func New(options ...storage.Option) storage.Manager
- func NewReadSeeker(ctx context.Context, input *s3.GetObjectInput, ...) io.ReadSeeker
- func Provider(options ...storage.Option) (storage.Manager, error)
- type AuthConfig
- type AwsConfigProvider
- type CompletedParts
- type Storager
- func (s *Storager) Close() error
- func (s *Storager) Copy(ctx context.Context, sourcePath, destBucket, destPath string, ...) error
- func (s *Storager) Create(ctx context.Context, destination string, mode os.FileMode, reader io.Reader, ...) error
- func (s *Storager) Delete(ctx context.Context, location string, options ...storage.Option) error
- func (s *Storager) Exists(ctx context.Context, location string, options ...storage.Option) (bool, error)
- func (s *Storager) FilterAuthOptions(options []storage.Option) []storage.Option
- func (s *Storager) Get(ctx context.Context, location string, options ...storage.Option) (os.FileInfo, error)
- func (s *Storager) IsAuthChanged(authOptions []storage.Option) bool
- func (s *Storager) List(ctx context.Context, location string, options ...storage.Option) ([]os.FileInfo, error)
- func (s *Storager) Move(ctx context.Context, sourcePath, destBucket, destPath string, ...) error
- func (s *Storager) Open(ctx context.Context, location string, options ...storage.Option) (io.ReadCloser, error)
- func (s *Storager) Upload(ctx context.Context, destination string, mode os.FileMode, reader io.Reader, ...) error
- type Writer
Examples ¶
Constants ¶
View Source
const Scheme = "s3"
Scheme s3 URL proto scheme
Variables ¶
This section is empty.
Functions ¶
func New ¶
New creates s3 manager
Example ¶
package main
import (
"context"
"fmt"
"io"
"log"
"github.com/viant/afsc/s3"
)
func main() {
service := s3.New()
ctx := context.Background()
reader, err := service.OpenURL(ctx, "s3://my-bucket/folder/asset")
if err != nil {
log.Fatal(err)
}
defer reader.Close()
data, err := io.ReadAll(reader)
if err != nil {
log.Fatal(err)
}
fmt.Printf("data: %s\n", data)
}
func NewReadSeeker ¶ added in v0.1.14
func NewReadSeeker(ctx context.Context, input *s3.GetObjectInput, downloader *s3manager.Downloader, partSize, size int) io.ReadSeeker
NewReadSeeker create a reader seeker
Types ¶
type AuthConfig ¶
type AuthConfig struct {
Key string `json:",omitempty"`
Secret string `json:",omitempty"`
Region string `json:",omitempty"`
AccountID string `json:"-"`
Token string `json:"-"`
Expiry time.Time `json:"-"`
RoleArn string `json:",omitempty"`
}
AuthConfig represents an auth config
func NewAuthConfig ¶
func NewAuthConfig(options ...storage.Option) (*AuthConfig, error)
NewAuthConfig returns new auth config from location
Example ¶
package main
import (
"context"
"fmt"
"io"
"log"
"os"
"path"
"github.com/viant/afs"
"github.com/viant/afs/option"
"github.com/viant/afsc/s3"
)
func main() {
authConfig, err := s3.NewAuthConfig(option.NewLocation(path.Join(os.Getenv("HOME"), ".aws/credentials")))
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// add default import _ "github.com/viant/afsc/s3"
service := afs.New()
reader, err := service.OpenURL(ctx, "s3://my-bucket/myfolder/asset.txt", authConfig)
data, err := io.ReadAll(reader)
if err != nil {
log.Fatal(err)
}
fmt.Printf("data: %s\n", data)
}
type AwsConfigProvider ¶
AwsConfigProvider represents aws config provider
type CompletedParts ¶ added in v0.1.14
type CompletedParts []types.CompletedPart
func (CompletedParts) Len ¶ added in v0.1.14
func (a CompletedParts) Len() int
func (CompletedParts) Less ¶ added in v0.1.14
func (a CompletedParts) Less(i, j int) bool
func (CompletedParts) Swap ¶ added in v0.1.14
func (a CompletedParts) Swap(i, j int)
type Storager ¶ added in v0.1.14
func NewStorager ¶ added in v0.1.14
func (*Storager) Create ¶ added in v0.1.14
func (s *Storager) Create(ctx context.Context, destination string, mode os.FileMode, reader io.Reader, isDir bool, options ...storage.Option) error
Create creates a resource
func (*Storager) Exists ¶ added in v0.1.14
func (s *Storager) Exists(ctx context.Context, location string, options ...storage.Option) (bool, error)
Exists returns true if object exists
func (*Storager) FilterAuthOptions ¶ added in v0.1.14
FilterAuthOptions filters auth options
func (*Storager) Get ¶ added in v0.1.14
func (s *Storager) Get(ctx context.Context, location string, options ...storage.Option) (os.FileInfo, error)
Get returns an object for supplied location
func (*Storager) IsAuthChanged ¶ added in v0.1.14
IsAuthChanged return true if auth has changes
func (*Storager) List ¶ added in v0.1.14
func (s *Storager) List(ctx context.Context, location string, options ...storage.Option) ([]os.FileInfo, error)
List list directory or returns a file info
Click to show internal directories.
Click to hide internal directories.