ginS3

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

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

Go to latest
Published: Feb 18, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

README

gin-s3

Build Status codecov Go Report Card GoDoc

a gin handler to fetch files from s3

Usage

Start using it

Download and install it:

$ go get github.com/tjamet/gin-s3

Import it in your code:

import "github.com/tjamet/gin-s3"
Canonical example:
package main

import (
	"time"

	"github.com/tjamet/gin-s3"
	"github.com/gin-gonic/gin"
)

func main() {
	router := gin.Default()
	// Gets credentials from the environment, the config files or the amazon instance
	router.Use(ginS3.NewDefault("test-bucket"))
	router.Run()
}
Using Specific access keys
func main() {
	router := gin.Default()
	router.Use(ginS3.NewDefault(
        "test-bucket",
        ginS3.AddProvider(
            &credentials.StaticProvider{
                Value: credentials.Value{
                    AccessKeyID:     "EXAMPLE",
                    SecretAccessKey: "EXAMPLEKEY",
                },
            })
        )
    )
	router.Run()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddProvider

func AddProvider(provider credentials.Provider) buildFunc

AddProvider adds a credential provider to the s3 client

func NewDefault

func NewDefault(bucket string, modifiers ...buildFunc) gin.HandlerFunc

NewDefault instanciates a new S3 handler with the default S3 client

func WithConfig

func WithConfig(config *aws.Config) buildFunc

WithConfig sets the s3 endpoint

func WithLogger

func WithLogger(logger Logger) buildFunc

WithLogger sets the logger for the handler

func WithRegion

func WithRegion(region string) buildFunc

WithRegion sets the default s3 region

Types

type Client

type Client interface {
	GetObject(*s3.GetObjectInput) (*s3.GetObjectOutput, error)
}

Client defines the methods of s3.S3 used by the middleware. It is provided as an interface to allow mocking for testing purposes

type Logger

type Logger interface {
	Printf(pattern string, v ...interface{})
}

Logger defines the interface a type must implement to log errors

type S3

type S3 struct {
	// Client holds
	Client Client
	Bucket string
	Logger Logger
}

S3 holds the configuration for the s3 handler

func (*S3) Handle

func (s *S3) Handle(c *gin.Context)

Handle implements a gin handler fetching the sources from a s3 bucket

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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