s3httpfilesystem

package module
v0.0.0-...-eb62dfd Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: GPL-3.0 Imports: 13 Imported by: 1

README

Go Report Card Documentation

s3httpfilesystem implements the http.FileSystem interface allowing an S3 bucket to be easily served over http.

Example:

package main

import (
	"net/http"

	s3 "github.com/jamesfcarter/s3httpfilesystem"
)

func main() {
	endpoint := "s3-us-west-2.amazonaws.com"
	bucket := "example"
	region := "us-west-2"
	// Credentials come from the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
	// environment variables.
	s3FileSystem := s3.New(endpoint, region, bucket)
	http.ListenAndServe(":80", http.FileServer(s3FileSystem))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// contains filtered or unexported fields
}

File implements the http.File interface for a S3 object or simulated directory.

func (*File) Close

func (f *File) Close() error

Close closes and removes a downloaded S3 object

func (*File) Read

func (f *File) Read(p []byte) (int, error)

Read reads from a downloaded S3 object as if it were a file

func (*File) Readdir

func (f *File) Readdir(count int) ([]os.FileInfo, error)

Readdir returns the contents of a simulated directory of S3 objects

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

Seek sets the offset for the next Read of a downloaded S3 object

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

Stat returns the FileInfo structure describing file.

type Filesystem

type Filesystem struct {
	// contains filtered or unexported fields
}

Filesystem implements the http.FileSystem interface for an S3 bucket.

func New

func New(endpoint, region, bucket string) *Filesystem

New builds and returns a new Filesystem accessing an S3. Credentials come from the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.

func NewWithS3

func NewWithS3(bucket string, mock s3Interface) *Filesystem

NewWithS3 takes an s3Interface and is used for testing

func (*Filesystem) Open

func (f *Filesystem) Open(path string) (http.File, error)

Open returns an http.File interface for an object or simulated directory within the S3 bucket.

Directories

Path Synopsis
mock
mock_s3interface
Package mock_s3httpfilesystem is a generated GoMock package.
Package mock_s3httpfilesystem is a generated GoMock package.

Jump to

Keyboard shortcuts

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