Azure Blob
Azure Blob 存储 是微软为云提供的对象存储解决方案。
注意: 需要 Go 1.19 或更高版本
目录
签名
func New(config ...Config) Storage
func (s *Storage) Get(key string) ([]byte, error)
func (s *Storage) Set(key string, val []byte, exp time.Duration) error
func (s *Storage) Delete(key string) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s *Storage) Conn() *azblob.Client
安装
Azure blob 存储驱动程序已在支持模块的最新 2 个 Go 版本上进行测试。因此,如果你还没有这样做,请确保先初始化一个。
go mod init github.com/<user>/<repo>
然后安装 azure blob 实现
go get github.com/gofiber/storage/azureblob/v2
示例
导入存储包。
import "github.com/gofiber/storage/azureblob/v2"
你可以使用以下方式创建存储
// Initialize default config
store := azureblob.New()
// Initialize custom config
store := azureblob.New(azureblob.Config{
Account: "test",
Container: "test",
Credentials: Credentials{
Account: "test",
Key: "YXp1cml0ZWtleQo=",
},
})
配置
type Config struct {
// Storage account name.
Account string
// Container name.
Container string
// Storage endpoint.
// Optional. Default: "https://STORAGEACCOUNTNAME.blob.core.windows.net"
Endpoint string
// Request timeout.
// Optional. Default is 0 (no timeout)
RequestTimeout time.Duration
// Reset clears any existing keys in existing container.
// 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
}
默认配置
var ConfigDefault = Config{
Account: "",
Container: "",
Endpoint: "",
RequestTimeout: 0,
Reset: false,
MaxAttempts: 3,
}