storage

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 12 Imported by: 0

README

storage — AWS S3 client

import "github.com/downsized-devs/sdk-go/storage"

Stability: Stable — see STABILITY.md

Wraps AWS SDK for Go (v1) for the common S3 operations: upload, download, delete, and presigned URLs.

Features

  • Upload, Download, Delete
  • GetPresignedUrl, GetPresignedUrlWithDuration
  • CreateUrlByKey for static URLs

Installation

go get github.com/downsized-devs/sdk-go/storage

Quick Start

s := storage.Init(storage.Config{
    AWS: storage.AWSS3Config{
        Region:    "ap-southeast-1",
        Bucket:    "my-bucket",
        AccessKey: "<KEY>",
        Secret:    "<SECRET>",
    },
}, log)

_ = s.Upload(ctx, "key/path.jpg", fileReader, "image/jpeg")
url, _ := s.GetPresignedUrl(ctx, "key/path.jpg")

API Reference

Symbol Signature
Init func Init(cfg Config, log logger.Interface) Interface
Interface.Upload (ctx, key string, body io.Reader, contentType string) error
Interface.Download (ctx, key string) ([]byte, error)
Interface.Delete (ctx, key string) error
Interface.GetPresignedUrl (ctx, key string) (string, error)
Interface.GetPresignedUrlWithDuration (ctx, key string, d time.Duration) (string, error)
Interface.CreateUrlByKey (key string) string

Configuration

Field Required Description
AWS.Region yes S3 region.
AWS.Bucket yes Default bucket.
AWS.AccessKey / AWS.Secret yes IAM credentials. Use IRSA / IAM-role-for-service-account in EKS instead when possible.

Error Handling

Errors are wrapped with codes third-party codes.

Dependencies

  • Internal: codes, errors, logger
  • External: github.com/aws/aws-sdk-go/aws, .../credentials, .../session, .../service/s3

Testing

go test ./storage/...

Contributing

See CONTRIBUTING.md. Migrating to AWS SDK v2 would be a major change — file an issue first.

  • local_storage — on-disk full-text index (different problem).
  • files — local-file helpers.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AWSS3Config

type AWSS3Config struct {
	Region          string
	BucketName      string
	AccessKeyID     string
	SecretAccessKey string
	PresignDuration time.Duration
}

type Config

type Config struct {
	AWSS3 AWSS3Config
}

type Interface

type Interface interface {
	Upload(ctx context.Context, key string, filename, filemimetype string, data []byte) (url string, err error)
	Download(ctx context.Context, url string) ([]byte, error)
	Delete(ctx context.Context, key string) error
	GetPresignedUrl(ctx context.Context, key string) (string, error)
	GetPresignedUrlWithDuration(ctx context.Context, key string, presignedDuration time.Duration) (string, error)
	CreateUrlByKey(key string) string
}

func Init

func Init(cfg Config, log logger.Interface) Interface

Jump to

Keyboard shortcuts

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