'修改了方法注释,新增了一个获取临时地址的方法'
This commit is contained in:
@@ -44,6 +44,4 @@ go get github.com/cowardmrx/go_aliyun_oss
|
|||||||
})
|
})
|
||||||
fmt.Println(isSuccess)
|
fmt.Println(isSuccess)
|
||||||
|
|
||||||
|
#详细使用方法请参照oss_test.go文件中的示例
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
4
file.go
4
file.go
@@ -24,7 +24,7 @@ type OssFileInterface interface {
|
|||||||
GetFileType() *OssFile
|
GetFileType() *OssFile
|
||||||
}
|
}
|
||||||
|
|
||||||
// file type transform
|
// FileTypeTransForm file type transform
|
||||||
//@title 文件类型转换
|
//@title 文件类型转换
|
||||||
func (ossFile *OssFile) FileTypeTransForm() (*OssFile,error) {
|
func (ossFile *OssFile) FileTypeTransForm() (*OssFile,error) {
|
||||||
var err error
|
var err error
|
||||||
@@ -100,7 +100,7 @@ func (ossFile *OssFile) FileTypeTransForm() (*OssFile,error) {
|
|||||||
return ossFile,nil
|
return ossFile,nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//split file type and generate file name
|
// GetFileType split file type and generate file name
|
||||||
//截取文件类型
|
//截取文件类型
|
||||||
func (ossFile *OssFile) GetFileType() *OssFile {
|
func (ossFile *OssFile) GetFileType() *OssFile {
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type AliOssConfigInterface interface {
|
|||||||
GetAccessibleUrl() string
|
GetAccessibleUrl() string
|
||||||
}
|
}
|
||||||
|
|
||||||
//check AliOssConfig value is exists
|
// CheckConfig check AliOssConfig value is exists
|
||||||
func (coon *AliOssConfig) CheckConfig() {
|
func (coon *AliOssConfig) CheckConfig() {
|
||||||
//check endPoint
|
//check endPoint
|
||||||
if coon.EndPoint == "" || len(coon.EndPoint) <= 0 {
|
if coon.EndPoint == "" || len(coon.EndPoint) <= 0 {
|
||||||
@@ -49,7 +49,7 @@ func (coon *AliOssConfig) CheckConfig() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//en: create oss connect client
|
// CreateOssConnect en: create oss connect client
|
||||||
//创建阿里云oss 链接客户端
|
//创建阿里云oss 链接客户端
|
||||||
func (coon *AliOssConfig) CreateOssConnect() *AliOssClient {
|
func (coon *AliOssConfig) CreateOssConnect() *AliOssClient {
|
||||||
//config check
|
//config check
|
||||||
@@ -82,7 +82,7 @@ func (coon *AliOssConfig) CreateOssConnect() *AliOssClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//get oss accessible url
|
// GetAccessibleUrl get oss accessible url
|
||||||
//拼接阿里云oss可访问地址
|
//拼接阿里云oss可访问地址
|
||||||
func (coon *AliOssConfig) GetAccessibleUrl() string {
|
func (coon *AliOssConfig) GetAccessibleUrl() string {
|
||||||
var domain string
|
var domain string
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ type AliOssClient struct {
|
|||||||
Client *oss.Bucket
|
Client *oss.Bucket
|
||||||
}
|
}
|
||||||
|
|
||||||
//推送文件到oss
|
// Put 推送文件到oss
|
||||||
//params: ossDir string `oss dir [要推送到的oss目录]` example: test/20201121/
|
//params: ossDir string `oss dir [要推送到的oss目录]` example: test/20201121/
|
||||||
//params: file interface `upload file resource [文件资源]`
|
//params: file interface `upload file resource [文件资源]`
|
||||||
//return string `oss file accessible uri [可访问地址]`
|
//return string `oss file accessible uri [可访问地址]`
|
||||||
@@ -52,7 +52,7 @@ func (client *AliOssClient) Put(ossDir string, file interface{},fileType string)
|
|||||||
return client.Domain + "/" + ossPath
|
return client.Domain + "/" + ossPath
|
||||||
}
|
}
|
||||||
|
|
||||||
//校验文件是否已经存在
|
// HasExists 校验文件是否已经存在
|
||||||
//check file already exists in oss server
|
//check file already exists in oss server
|
||||||
//params: ossFilePath string `file oss path [文件的oss的路径]`
|
//params: ossFilePath string `file oss path [文件的oss的路径]`
|
||||||
func (client *AliOssClient) HasExists(ossFilePath string) bool {
|
func (client *AliOssClient) HasExists(ossFilePath string) bool {
|
||||||
@@ -67,7 +67,7 @@ func (client *AliOssClient) HasExists(ossFilePath string) bool {
|
|||||||
return isExists
|
return isExists
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除文件-单文件删除
|
// Delete 删除文件-单文件删除
|
||||||
//delete one file in oss
|
//delete one file in oss
|
||||||
//params ossPath string `file oss path [文件的oss路径]`
|
//params ossPath string `file oss path [文件的oss路径]`
|
||||||
//return bool
|
//return bool
|
||||||
@@ -83,7 +83,7 @@ func (client *AliOssClient) Delete(ossFilePath string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除文件-多文件删除
|
// DeleteMore 删除文件-多文件删除
|
||||||
//delete more file in oss
|
//delete more file in oss
|
||||||
//params ossPath []string `file oss path array [文件的oss路径数组]`
|
//params ossPath []string `file oss path array [文件的oss路径数组]`
|
||||||
//return bool
|
//return bool
|
||||||
@@ -96,4 +96,27 @@ func (client *AliOssClient) DeleteMore(ossFilePath []string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTemporaryUrl 获取文件临时地址
|
||||||
|
// path string 文件路径
|
||||||
|
// expireInSecond int64 多久后过期 单位: 秒,默认 60
|
||||||
|
func (client *AliOssClient) GetTemporaryUrl(path string,expireInSecond int64) string {
|
||||||
|
|
||||||
|
var expireTime int64
|
||||||
|
|
||||||
|
if expireInSecond <= 0 {
|
||||||
|
expireTime = 60
|
||||||
|
} else {
|
||||||
|
expireTime = expireInSecond
|
||||||
|
}
|
||||||
|
|
||||||
|
signUrl,err := client.Client.SignURL(path,oss.HTTPGet,expireTime)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic("generate sign url failed:" + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return signUrl
|
||||||
|
|
||||||
}
|
}
|
||||||
15
oss_test.go
15
oss_test.go
@@ -94,3 +94,18 @@ func TestAliOssClient_DeleteMore(t *testing.T) {
|
|||||||
fmt.Println(deleteRes)
|
fmt.Println(deleteRes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAliOssClient_GetTemporaryUrl(t *testing.T) {
|
||||||
|
ossConfig := &AliOssConfig{
|
||||||
|
EndPoint: "",
|
||||||
|
AccessKeyId: "",
|
||||||
|
AccessKeySecret: "",
|
||||||
|
BucketName: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
client := ossConfig.CreateOssConnect()
|
||||||
|
|
||||||
|
singUrl := client.GetTemporaryUrl("logo/8497b913-2a79-58a1-984b-c25827f8212e.png",180)
|
||||||
|
|
||||||
|
fmt.Println(singUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user