Skip to content
Snippets Groups Projects
Select Git revision
  • 1940f14b79715ad77396c154f691fbaff2f0e216
  • main default protected
  • trading_hours
  • refactor_trading_hours
  • audit_cleaning_cater_for_non_struct_fields
  • remove-info-logs
  • sl-refactor
  • 18-use-scan-for-param-values
  • 17-order-search-results
  • 4-simplify-framework-2
  • 1-http-error
  • v1.297.0
  • v1.296.0
  • v1.295.0
  • v1.294.0
  • v1.293.0
  • v1.292.0
  • v1.291.0
  • v1.290.0
  • v1.289.0
  • v1.288.0
  • v1.287.0
  • v1.286.0
  • v1.285.0
  • v1.284.0
  • v1.283.0
  • v1.282.0
  • v1.281.0
  • v1.280.0
  • v1.279.0
  • v1.278.0
31 results

s3.go

Blame
  • s3.go 14.07 KiB
    package s3
    
    import (
    	"bytes"
    	"context"
    	"encoding/binary"
    	"fmt"
    	"net/url"
    	"os"
    	"path"
    	"strings"
    	"time"
    
    	"github.com/aws/aws-sdk-go-v2/config"
    	"github.com/aws/aws-sdk-go-v2/credentials"
    	"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/secrets_manager"
    
    	std_errors "errors"
    
    	"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/errors"
    
    	"github.com/aws/aws-sdk-go-v2/aws"
    	"github.com/aws/aws-sdk-go-v2/service/s3"
    	"github.com/aws/aws-sdk-go-v2/service/s3/types"
    	"github.com/google/uuid"
    )
    
    // S3UploadResponse defines the structure of a standard JSON response to a PDF/CSV/etc request.
    type S3UploadResponse struct {
    	URL      string `json:"url"`
    	Filename string `json:"filename"`
    	Bucket   string `json:"bucket"`
    	FileSize int    `json:"file_size"`
    }
    
    type S3UploadSettings struct {
    	MimeType              MIMEType
    	RetrieveSignedUrl     bool
    	ExpiryDuration        *time.Duration // Used to set expiry datetime of download links. NB: does not affect deletion of object from S3 bucket.
    	AddContentDisposition bool
    	FilePath              string
    	FileName              string
    	FileExt               string
    	InsertUUID            bool
    }
    
    // Duration constants
    const (
    	S3ExpiryDuration1Day  time.Duration = 24 * time.Hour
    	S3ExpiryDuration7Days time.Duration = 7 * 24 * time.Hour
    )
    
    type MIMEType string
    
    const (
    	// MIMETypePDF defines the constant for the PDF MIME type.
    	MIMETypePDF MIMEType = "application/pdf"
    
    	// MIMETypeCSV defines the constant for the CSV MIME type.
    	MIMETypeCSV MIMEType = "text/csv"
    
    	// MIMETypeZIP defines the constant for the ZIP MIME type.
    	MIMETypeZIP MIMEType = "application/zip"
    
    	// MIMETypeJSON defines the constant for the JSON MIME type.
    	MIMETypeJSON MIMEType = "application/json"
    
    	// MIMETypeText defines the constant for the Plain text MIME type.
    	MIMETypeText MIMEType = "text/plain"