S3Uploader

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 13 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Simple go library for uploading to S3. Enables auto bucket creation.

package main

import (
	"github.com/suhailgupta03/go-s3-uploader"
	"github.com/zerodha/logf"
	"time"
)

func main() {
	lo := logf.New(logf.Opts{
		EnableColor:          true,
		Level:                logf.DebugLevel,
		CallerSkipFrameCount: 3,
		EnableCaller:         true,
		TimestampFormat:      time.RFC3339Nano,
		DefaultFields:        []any{"scope", "example"},
	})
	s := S3Uploader.S3{
		// Optional if you want to point to a specific path
		AWSConfig: &S3Uploader.Config{
			AWSConfigFile:            "/go-s3-uploader/config",
			AWSSharedCredentialsFile: "/go-s3-uploader/credentials",
		},
		BucketName: "test-foo-xyz",
		RetentionConfig: &S3Uploader.RetentionConfig{
			Use:  true,
			Time: time.Now().AddDate(0, 0, 1),
		},
		Lo: &lo,
	}

	testData := "this is some data"
	fileIdentifier := "file-id"
	uploadId, _ := s.UploadFile([]byte(testData), fileIdentifier)
	if uploadId != nil {
		lo.Info("Success!", "upload-id", *uploadId)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	AWSConfigFile            string
	AWSSharedCredentialsFile string
}

type RetentionConfig

type RetentionConfig struct {
	Use  bool
	Time time.Time
}

type S3

type S3 struct {
	// AWSConfig Specifically use to pass the file location
	// of credentials and config. Ignore if the variables are
	// already provided to the environment
	AWSConfig       *Config
	BucketName      string
	RetentionConfig *RetentionConfig
	Lo              *logf.Logger
	// contains filtered or unexported fields
}

func (*S3) UploadFile

func (s3 *S3) UploadFile(data []byte, identifier string) (*UploadId, error)

UploadFile uploads to S3 and generates the upload id

type UploadId

type UploadId string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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