go-object-storage 是一个用go开发的针对主流云服务商对象存储SDK集成包。其实现了文件路径自动生产,不同存储引擎简单配置即可使用,欢迎使用。
$ go get -u github.com/qwxingzhe/go-object-storage
package main
import (
"fmt"
objectstorage "github.com/qwxingzhe/go-object-storage"
objectstoragedrives "github.com/qwxingzhe/go-object-storage/drives"
"github.com/qwxingzhe/go-package-demo/config"
)
// 配置存储引擎
func GetObjectStorage(isAutomaticProductionPath bool) *objectstorage.ObjectStorage {
return &objectstorage.ObjectStorage{
Drive: objectstoragedrives.Kodo{
AccessKey: config.KodoConfig.AccessKey,
SecretKey: config.KodoConfig.SecretKey,
Bucket: config.KodoConfig.Bucket,
},
IsAutomaticProductionPath: isAutomaticProductionPath,
FilePathPrefix: "test/",
IsAppendExt: false,
BaseUrl: "http://qynr9haq9.hd-bkt.clouddn.com/",
}
}
func main() {
// 转存网络文件
url := "https://tenfei03.cfp.cn/creative/vcg/veer/800/new/VCG41N813911068.jpg"
fileInfo, _ := GetObjectStorage(true).PutNetFile(url)
fmt.Println(fileInfo)
}
上传指定内容,指定存储路径
localFile := "111111111111111"
key := "temp/11111111111.txt"
fileInfo, err := GetObjectStorage(false).SetFilePath(key).PutStr(localFile)
if err != nil {
t.Errorf(err.Error())
}
fmt.Println(fileInfo)
上传本地文件
localFile := "./golang.jpg"
fileInfo, err := GetObjectStorage(true).PutFile(localFile)
if err != nil {
t.Errorf(err.Error())
}
fmt.Println(fileInfo)
参数 | 说明 |
---|---|
Drive | 对象存储驱动 |
IsAutomaticProductionPath | 是否自动生产文件路径 |
FilePathPrefix | 指定文件存储前缀 |
IsAppendExt | 是否自动拼接文件名后缀 |
BaseUrl | 基础url路径 |
- 七牛云 kodo
- 阿里云 oos
- 腾讯云 cos
- Amazon S3
MIT