mirror of
https://github.com/gofiber/storage.git
synced 2025-10-04 08:16:36 +08:00

* implement basic s3 operations * add request timeout contexts * remove close channel * update Config comments * fix README * stuff * set config options in s3.Storage * add s3 workflow for github actions * Bump SDK to aws/aws-sdk-go-v2 * update * Add missing README. * Add security workflows for s3. * Add tests for S3 * update update update update update update update update update update update update update update * update * Code reviews. Co-authored-by: Paul Cento <prscento@uwaterloo.ca> Co-authored-by: Alex Bakker <abakks@hotmail.com> Co-authored-by: Muhammed Efe Çetin <efectn@protonmail.com>
70 lines
1.3 KiB
Go
70 lines
1.3 KiB
Go
package s3
|
|
|
|
import "time"
|
|
|
|
// Config defines the config for storage.
|
|
type Config struct {
|
|
// S3 bucket name
|
|
Bucket string
|
|
|
|
// AWS endpoint
|
|
Endpoint string
|
|
|
|
// AWS region
|
|
Region string
|
|
|
|
// Request timeout
|
|
//
|
|
// Optional. Default is 0 (no timeout)
|
|
RequestTimeout time.Duration
|
|
|
|
// Reset clears any existing keys in existing Bucket
|
|
//
|
|
// Optional. Default is false
|
|
Reset bool
|
|
|
|
// Credentials overrides AWS access key and AWS secret access key. Not recommended.
|
|
//
|
|
// Optional. Default is Credentials{}
|
|
Credentials Credentials
|
|
|
|
// The maximum number of times requests that encounter retryable failures should be attempted.
|
|
//
|
|
// Optional. Default is 3
|
|
MaxAttempts int
|
|
}
|
|
|
|
type Credentials struct {
|
|
AccessKey string
|
|
SecretAccessKey string
|
|
}
|
|
|
|
// ConfigDefault is the default config
|
|
var ConfigDefault = Config{
|
|
Bucket: "",
|
|
Region: "",
|
|
Endpoint: "",
|
|
Credentials: Credentials{},
|
|
MaxAttempts: 3,
|
|
RequestTimeout: 0,
|
|
Reset: false,
|
|
}
|
|
|
|
// Helper function to set default values
|
|
func configDefault(config ...Config) Config {
|
|
// Return default config if nothing provided
|
|
if len(config) < 1 {
|
|
return ConfigDefault
|
|
}
|
|
|
|
// Override default config
|
|
cfg := config[0]
|
|
|
|
// Set default values
|
|
if cfg.Bucket == "" {
|
|
cfg.Bucket = ConfigDefault.Bucket
|
|
}
|
|
|
|
return cfg
|
|
}
|