s3lib

package module
v0.0.0-...-73a03de Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 13 Imported by: 0

README

s3lib

golang library to access S3 compatile object storage on AWS or other providers like Vultr or Linode

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	S3Region         string
	Endpoint         string
	AccessKey        string
	SecretKey        string
	S3ForcePathStyle bool
}

type S3Object

type S3Object struct {
	Filename     string
	Etag         string
	LastModified time.Time
	Size         int64
}

type S3Session

type S3Session struct {
	*s3.S3
}

func GetSession

func GetSession(cfg *Config) (*S3Session, error)

GetSession creates a new AWS session. Can be reused to upload multiple files

func (*S3Session) GetFile

func (s *S3Session) GetFile(w http.ResponseWriter, bucket, filekey string, cacheDurinSeconds int) (int64, error)

func (*S3Session) Hash

func (s *S3Session) Hash(filekey, lastmodified string) string

md5Str gives MD5 hash of given string and salt

func (*S3Session) HeadFile

func (s *S3Session) HeadFile(bucket, filekey string) (time.Time, error)

HeadFile make head request to S3 storage and get metadata of file without getting file contents

func (*S3Session) ListObjects

func (s *S3Session) ListObjects(bucketName, folder string) ([]S3Object, error)

func (*S3Session) RemoveFile

func (s *S3Session) RemoveFile(bucket, remoteFileName string) error

RemoveFile will remove given remote-file from S3 storage

func (*S3Session) RemoveFolder

func (s *S3Session) RemoveFolder(bucket, folder string) error

RemoveFolder will remove given folder and all of it's files from S3

func (*S3Session) UploadFile

func (s *S3Session) UploadFile(fileToUpload, remoteFileName, bucket, contentType string) error

UploadFile will upload a single file to S3, it will require a pre-built aws session and will set file info like content type and encryption on the uploaded file.

func (*S3Session) UploadLargeFile

func (s *S3Session) UploadLargeFile(fileToUpload, remoteFileName, bucket, contentType string) error

UploadLargeFile will upload a single large file to S3 as multipart uplaod, it will require a pre-built aws session

Jump to

Keyboard shortcuts

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