From c9ce74c4403c26b00e8468076ce02f071042fb34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Tue, 17 May 2022 10:47:06 +0800 Subject: [PATCH] init --- .drone.yml | 11 +++++++++++ .gitignore | 8 ++++++++ README.md | 25 ++++++++++++++++++++++++ aliyun.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ baidu.go | 1 + go.mod | 12 ++++++++++++ go.sum | 15 ++++++++++++++ huaweicloud.go | 1 + ksyun.go | 1 + qiniu.go | 1 + tencent.go | 1 + upyun.go | 1 + version.go | 3 +++ version_test.go | 7 +++++++ 14 files changed, 139 insertions(+) create mode 100644 .drone.yml create mode 100644 .gitignore create mode 100644 README.md create mode 100644 aliyun.go create mode 100644 baidu.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 huaweicloud.go create mode 100644 ksyun.go create mode 100644 qiniu.go create mode 100644 tencent.go create mode 100644 upyun.go create mode 100644 version.go create mode 100644 version_test.go diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..511f0fc --- /dev/null +++ b/.drone.yml @@ -0,0 +1,11 @@ +kind: pipeline +type: docker +name: clone + +steps: + - name: test-golang + image: golang:1.18 + commands: + - go env -w GO111MODULE=on + - go env -w GOPROXY=https://goproxy.cn,direct + - go test -v ./... \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..442794a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.env +.git +.svn +.idea +.vscode +*.log +gomod.sh +/vendor/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6b7e72c --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +

+Golang Storage +

+ +📦 Golang Storage + +[comment]: <> (go) +[![godoc](https://pkg.go.dev/badge/go.dtapp.net/gostorage?status.svg)](https://pkg.go.dev/go.dtapp.net/gostorage) +[![goproxy.cn](https://goproxy.cn/stats/go.dtapp.net/gostorage/badges/download-count.svg)](https://goproxy.cn/stats/go.dtapp.net/gostorage) +[![goreportcard.com](https://goreportcard.com/badge/go.dtapp.net/gostorage )](https://goreportcard.com/report/go.dtapp.net/gostorage) +[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/go.dtapp.net/gostorage) + +#### 安装使用 + +```go +go get -v -u go.dtapp.net/gostorage +``` + +#### 导入 + +```go +import ( + "go.dtapp.net/gostorage" +) +``` \ No newline at end of file diff --git a/aliyun.go b/aliyun.go new file mode 100644 index 0000000..cd599a5 --- /dev/null +++ b/aliyun.go @@ -0,0 +1,52 @@ +package gostorage + +import ( + "github.com/aliyun/aliyun-oss-go-sdk/oss" + "io" +) + +// AliYun 阿里云 OSS 存储 +type AliYun struct { + Endpoint string + AccessKeyId string + AccessKeySecret string + error error // 错误信息 + client *oss.Client // 驱动 + bucket *oss.Bucket // 存储空间 +} + +// NewAliYun 初始化 +func NewAliYun(endpoint string, accessKeyId string, accessKeySecret string) *AliYun { + app := &AliYun{Endpoint: endpoint, AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret} + app.client, app.error = oss.New(endpoint, accessKeyId, accessKeySecret) + return app +} + +// Bucket 存储空间 +func (c *AliYun) Bucket(name string) *AliYun { + c.bucket, c.error = c.client.Bucket(name) + return c +} + +// FileInfo 上传文件的信息 +type FileInfo struct { + Path string // 文件路径 + Name string // 文件名称 + Url string // 文件地址 +} + +// PutObject 上传文件流 +// @param file 文件流 +// @param filePath 文件路径 +// @param fileName 文件名称 +func (c *AliYun) PutObject(file io.Reader, filePath, fileName string) (resp FileInfo, err error) { + objectKey := filePath + if fileName != "" { + objectKey = filePath + "/" + fileName + } + err = c.bucket.PutObject(objectKey, file) + resp.Path = filePath + resp.Name = fileName + resp.Url = objectKey + return +} diff --git a/baidu.go b/baidu.go new file mode 100644 index 0000000..a613a45 --- /dev/null +++ b/baidu.go @@ -0,0 +1 @@ +package gostorage diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6006b5c --- /dev/null +++ b/go.mod @@ -0,0 +1,12 @@ +module go.dtapp.net/gostorage + +go 1.18 + +require github.com/aliyun/aliyun-oss-go-sdk v2.2.3+incompatible + +require ( + github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect + github.com/satori/go.uuid v1.2.0 // indirect + golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..bd8fbaa --- /dev/null +++ b/go.sum @@ -0,0 +1,15 @@ +github.com/aliyun/aliyun-oss-go-sdk v2.2.3+incompatible h1:KlwIELiuuvj7uMeEXrgXecPE3+xz/gGsDSnhL6Eztq0= +github.com/aliyun/aliyun-oss-go-sdk v2.2.3+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= +github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f h1:ZNv7On9kyUzm7fvRZumSyy/IUiSC7AzL0I1jKKtwooA= +github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= +github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +golang.org/x/time v0.0.0-20220411224347-583f2d630306 h1:+gHMid33q6pen7kv9xvT+JRinntgeXO2AeZVd0AWD3w= +golang.org/x/time v0.0.0-20220411224347-583f2d630306/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/huaweicloud.go b/huaweicloud.go new file mode 100644 index 0000000..a613a45 --- /dev/null +++ b/huaweicloud.go @@ -0,0 +1 @@ +package gostorage diff --git a/ksyun.go b/ksyun.go new file mode 100644 index 0000000..a613a45 --- /dev/null +++ b/ksyun.go @@ -0,0 +1 @@ +package gostorage diff --git a/qiniu.go b/qiniu.go new file mode 100644 index 0000000..a613a45 --- /dev/null +++ b/qiniu.go @@ -0,0 +1 @@ +package gostorage diff --git a/tencent.go b/tencent.go new file mode 100644 index 0000000..a613a45 --- /dev/null +++ b/tencent.go @@ -0,0 +1 @@ +package gostorage diff --git a/upyun.go b/upyun.go new file mode 100644 index 0000000..a613a45 --- /dev/null +++ b/upyun.go @@ -0,0 +1 @@ +package gostorage diff --git a/version.go b/version.go new file mode 100644 index 0000000..7405547 --- /dev/null +++ b/version.go @@ -0,0 +1,3 @@ +package gostorage + +const Version = "1.0.0" diff --git a/version_test.go b/version_test.go new file mode 100644 index 0000000..d5d2be1 --- /dev/null +++ b/version_test.go @@ -0,0 +1,7 @@ +package gostorage + +import "testing" + +func TestVersion(t *testing.T) { + t.Log(Version) +}