storage

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 13 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{
    AWSS3: storage.AWSS3Config{
        Region:          "ap-southeast-1",
        BucketName:      "my-bucket",
        AccessKeyID:     "<KEY>",
        SecretAccessKey: "<SECRET>",
        PresignDuration: 15 * time.Minute,
    },
}, log)

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

API Reference

Symbol Signature
Init func Init(cfg Config, log logger.Interface) Interface
Interface.Upload (ctx, key string, filename, contentType string, data []byte) (url string, err 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
AWSS3.Region yes S3 region.
AWSS3.BucketName yes Default bucket.
AWSS3.AccessKeyID / AWSS3.SecretAccessKey yes IAM credentials. Use IRSA / IAM-role-for-service-account in EKS instead when possible.
AWSS3.PresignDuration no Default expiry used by GetPresignedUrl.

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.

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

Documentation

Overview

Package storage wraps the AWS S3 v1 SDK with a small Interface covering upload, download, delete, presigned URL generation, and static URL construction.

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
}

AWSS3Config carries the bucket, region, IAM credentials, and the default presign duration applied by GetPresignedUrl.

type Config

type Config struct {
	AWSS3 AWSS3Config
}

Config wraps the AWS-specific options consumed by Init.

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
}

Interface is the public surface of the storage package. Mockable for tests.

func Init

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

Init constructs an S3-backed storage client. It calls log.Fatal when the configured credentials are empty so misconfigured services fail fast at startup rather than at the first request.

Jump to

Keyboard shortcuts

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