kits3

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeHttpHandler

func MakeHttpHandler(endpoint endpoint.Endpoint, middleware endpoint.Middleware) http.Handler

MakeHttpHandler creates a go kit transport in http for *UploadService.

func MakeUploadEndpoint

func MakeUploadEndpoint(uploader Uploader) endpoint.Endpoint

MakeUploadEndpoint creates a Upload endpoint

func Middleware

func Middleware(logger log.Logger, env contract.Env) endpoint.Middleware

Middleware adds logging and error handling to the endpoint.

func NewClient

func NewClient(uri *url.URL) *httptransport.Client

NewClient creates a go kit style http client to *UploadService

Types

type ClientUploader

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

ClientUploader implements the Uploader interface. It uploads files to the remote server.

func NewClientUploader

func NewClientUploader(client *httptransport.Client) *ClientUploader

NewClientUploader creates a *ClientUploader

func NewClientUploaderFromUrl

func NewClientUploaderFromUrl(uri *url.URL) *ClientUploader

NewClientUploaderFromUrl creates a *ClientUploader from the url of the remote *UploadService

func (ClientUploader) Upload

func (c ClientUploader) Upload(ctx context.Context, name string, reader io.Reader) (newUrl string, err error)

Upload reads all bytes in reader, and send them to remote server under the given filename. The Url of the uploaded file will be returned.

type Module

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

Module is a s3 module that adds a file upload path. It uses the default configuration.

func New

func New(manager *ots3.Manager, logger log.Logger, env contract.Env) Module

New creates the s3 module

func (Module) ProvideHTTP

func (m Module) ProvideHTTP(router *mux.Router)

ProvideHttp adds a "/upload" path to router

type Request

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

Request models a go kit request in UploadEndpoint

type Response

type Response struct {
	Data struct {
		Url string `json:"url"`
	} `json:"data"`
	Code    int    `json:"code"`
	Message string `json:"message,omitempty"`
}

Response models a go kit Response in UploadEndpoint

type UploadService

type UploadService struct {
	Logger log.Logger
	S3     *ots3.Manager
}

An UploadService is a go kit service to handle file upload

func (*UploadService) Upload

func (s *UploadService) Upload(ctx context.Context, name string, reader io.Reader) (newUrl string, err error)

Upload reads all bytes from reader, and upload then to S3 as the provided name. The url will be returned.

type Uploader

type Uploader interface {
	// Upload the bytes from io.Reader with a given filename to a server, and returns the url and error.
	Upload(ctx context.Context, name string, reader io.Reader) (string, error)
}

Uploader models UploadService

Jump to

Keyboard shortcuts

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