s3

package
v0.0.0-...-3a9ac50 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 10 Imported by: 0

README

S3 utilities

package main

import (
	"fmt"

	s4 "github.com/nguyengg/golambda/s3"
)

func main() {
	uri, _ := s4.Parse("s3://my-bucket[1234]/prefix/to/path")
	fmt.Println(uri.Append("my-key.json"))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToGetObject

func AddToGetObject(input *s3.GetObjectInput, header http.Header) *s3.GetObjectInput

AddToGetObject adds conditional request headers to the s3.GetObjectInput and return the same input.

Specifically, these headers are parsed from the "header" argument:

  • If-Match and If-None-Match
  • If-Modified-Since and If-Unmodified-Since
  • Range

func AddToHeadObject

func AddToHeadObject(input *s3.HeadObjectInput, header http.Header) *s3.HeadObjectInput

AddToHeadObject adds conditional request headers to the s3.HeadObjectInput and return the same input.

Specifically, these headers are parsed from the "header" argument:

  • If-Match and If-None-Match
  • If-Modified-Since and If-Unmodified-Since
  • Range

func HeadersFromGetObjectOutput

func HeadersFromGetObjectOutput(output *s3.GetObjectOutput, cb func(k, v string))

HeadersFromGetObjectOutput parses response headers from the s3.GetObjectOutput and passes it to the callback.

func HeadersFromHeadObjectOutput

func HeadersFromHeadObjectOutput(output *s3.HeadObjectOutput, cb func(k, v string))

HeadersFromHeadObjectOutput parses response headers from the s3.HeadObjectOutput and passes it to the callback.

func IsNoSuchKey

func IsNoSuchKey(err error) bool

IsNoSuchKey returns true if the error's smithy.APIError.ErrorCode returns "NoSuchKey".

The documentation at https://aws.github.io/aws-sdk-go-v2/docs/handling-errors/#api-error-responses doesn't work for [github.com/aws/aws-sdk-go-v2/service/s3/types#NoSuchKey] (maybe you have better luck?) but this works for me.

Types

type URIWithOwner

type URIWithOwner struct {
	Bucket              string
	Key                 string
	ExpectedBucketOwner string
}

URIWithOwner contains required Bucket, Key, and ExpectedBucketOwner fields.

func Parse

func Parse(rawURL string) (value URIWithOwner, err error)

Parse parses a URL in expected format s3://bucket[owner]/key.

Only the bucket name and expected bucket owner is required. The key can be empty, or can be a prefix that possibly ends in "/".

func (URIWithOwner) Append

func (u URIWithOwner) Append(key string) URIWithOwner

Append creates a new URIWithOwner by appending the given key to the existing key.

The new key is a simple concatenation of existing key + new key without any '/' separator.

func (URIWithOwner) Get

Get decorates the given s3.GetObjectInput the fields from the URIWithOwner.

If given a nil input, a new one will be created.

func (URIWithOwner) GoString

func (u URIWithOwner) GoString() string

GoString returns s3://bucket[owner]/key, or s3://bucket[owner] if key is empty string.

func (URIWithOwner) Head

Head decorates the given s3.HeadObjectInput the fields from the URIWithOwner.

If given a nil input, a new one will be created.

func (URIWithOwner) Put

Put decorates the given s3.PutObjectInput the fields from the URIWithOwner.

If given a nil input, a new one will be created.

func (URIWithOwner) String

func (u URIWithOwner) String() string

String returns s3://bucket/key, or s3://bucket if key is empty string.

Jump to

Keyboard shortcuts

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