s3middleware

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2020 License: Apache-2.0 Imports: 14 Imported by: 1

README

echo-s3-middleware

This echo middleware provides a static file store backed by S3.

GitHub Actions status Go Report Card Documentation

Example

e := echo.New()
e.Pre(echomiddleware.AddTrailingSlash()) // required to ensure trailing slash is appended

fs := s3middleware.New(s3middleware.FilesConfig{
  Region: "us-east-1",    // can also be assigned using AWS_REGION environment variable
  SPA: true,              // enable fallback which will try Index if the first path is not found
  Index: "login.html",
  Summary: func(ctx context.Context, data map[string]interface{}) {
    log.Printf("processed s3 request: %+v", data)
  },
  OnErr: func(ctx context.Context, err error) {
    log.Printf("failed to process s3 request: %+v", err)
  },
})

// serve static files from the supplied bucket
e.Use(fs.StaticBucket("somebucket"))

License

This code was authored by Mark Wolfe and licensed under the Apache 2.0 license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FilesConfig

type FilesConfig struct {
	// Skipper defines a function to skip middleware
	echomiddleware.Skipper
	// Region The region used to configure the aws client
	Region string
	// HeaderXRequestID Name of the request id header to include in callbacks, defaults to echo.HeaderXRequestID
	HeaderXRequestID string
	// Enable SPA mode by forwarding all not-found requests to root so that
	// SPA (single-page application) can handle the routing.
	SPA bool
	// Index file for serving a directory in SPA mode.
	Index string
	// Summary provides a callback which provide a summary of what was successfully processed by s3
	Summary func(ctx context.Context, evt map[string]interface{})
	// OnErr is called if there is an issue processing the s3 request
	OnErr func(ctx context.Context, err error)
}

FilesConfig defines the config for the middleware

type FilesStore

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

FilesStore manages the s3 client

func New

func New(config FilesConfig) *FilesStore

New create a new FilesStore backed by s3

func (*FilesStore) StaticBucket

func (fs *FilesStore) StaticBucket(s3Bucket string) echo.MiddlewareFunc

StaticBucket new static file server using the supplied s3 bucket

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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