'修改了方法注释,新增了一个获取临时地址的方法'

This commit is contained in:
coward
2021-06-02 19:57:25 +08:00
parent d89ca3242c
commit 20fae36533
5 changed files with 48 additions and 12 deletions

View File

@@ -44,6 +44,4 @@ go get github.com/cowardmrx/go_aliyun_oss
})
fmt.Println(isSuccess)
#详细使用方法请参照oss_test.go文件中的示例

View File

@@ -24,7 +24,7 @@ type OssFileInterface interface {
GetFileType() *OssFile
}
// file type transform
// FileTypeTransForm file type transform
//@title 文件类型转换
func (ossFile *OssFile) FileTypeTransForm() (*OssFile,error) {
var err error
@@ -100,7 +100,7 @@ func (ossFile *OssFile) FileTypeTransForm() (*OssFile,error) {
return ossFile,nil
}
//split file type and generate file name
// GetFileType split file type and generate file name
//截取文件类型
func (ossFile *OssFile) GetFileType() *OssFile {

View File

@@ -20,7 +20,7 @@ type AliOssConfigInterface interface {
GetAccessibleUrl() string
}
//check AliOssConfig value is exists
// CheckConfig check AliOssConfig value is exists
func (coon *AliOssConfig) CheckConfig() {
//check endPoint
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 链接客户端
func (coon *AliOssConfig) CreateOssConnect() *AliOssClient {
//config check
@@ -82,7 +82,7 @@ func (coon *AliOssConfig) CreateOssConnect() *AliOssClient {
}
}
//get oss accessible url
// GetAccessibleUrl get oss accessible url
//拼接阿里云oss可访问地址
func (coon *AliOssConfig) GetAccessibleUrl() string {
var domain string

View File

@@ -11,7 +11,7 @@ type AliOssClient struct {
Client *oss.Bucket
}
//推送文件到oss
// Put 推送文件到oss
//params: ossDir string `oss dir [要推送到的oss目录]` example: test/20201121/
//params: file interface `upload file resource [文件资源]`
//return string `oss file accessible uri [可访问地址]`
@@ -52,7 +52,7 @@ func (client *AliOssClient) Put(ossDir string, file interface{},fileType string)
return client.Domain + "/" + ossPath
}
//校验文件是否已经存在
// HasExists 校验文件是否已经存在
//check file already exists in oss server
//params: ossFilePath string `file oss path [文件的oss的路径]`
func (client *AliOssClient) HasExists(ossFilePath string) bool {
@@ -67,7 +67,7 @@ func (client *AliOssClient) HasExists(ossFilePath string) bool {
return isExists
}
//删除文件-单文件删除
// Delete 删除文件-单文件删除
//delete one file in oss
//params ossPath string `file oss path [文件的oss路径]`
//return bool
@@ -83,7 +83,7 @@ func (client *AliOssClient) Delete(ossFilePath string) bool {
return true
}
//删除文件-多文件删除
// DeleteMore 删除文件-多文件删除
//delete more file in oss
//params ossPath []string `file oss path array [文件的oss路径数组]`
//return bool
@@ -97,3 +97,26 @@ func (client *AliOssClient) DeleteMore(ossFilePath []string) bool {
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
}

View File

@@ -94,3 +94,18 @@ func TestAliOssClient_DeleteMore(t *testing.T) {
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)
}