GoTool 支持阿里云、腾讯云、本地三种形式的静态云存储,通过配置可以灵活地对静态文件进行同步和删除操作。
import (
"github.com/cnlesscode/gotool/cloud/static"
)
staticCloudConfig := &static.Config{
Type: "Local",
BaseUrl: "http://localhost/",
}
staticCloudConfig := &static.Config{
Type: "AliOSS",
Endpoint: "oss-cn-beijing.aliyuncs.com",
KeyId: "******",
Secret: "******",
BucketName: "阿里云 BucketName",
BaseUrl: "https://static.graceui.com/",
}
staticCloudConfig := &static.Config{
Type: "TencentCOS",
Endpoint: "https://test-***.cos.ap-nanjing.myqcloud.com",
KeyId: "******",
Secret: "******",
BaseUrl: "https://test-***.cos.ap-nanjing.myqcloud.com",
}
函数功能 : 将本地文件同步到云
返回格式 : error
package main
import (
"fmt"
"github.com/cnlesscode/gotool/cloud/static"
)
func main() {
staticCloudConfig := &static.Config{
Type: "TencentCOS",
Endpoint: "https://test-***.cos.ap-nanjing.myqcloud.com",
KeyId: "******",
Secret: "******",
BaseUrl: "https://test-***.cos.ap-nanjing.myqcloud.com",
}
err := static.UploadFile(staticCloudConfig, "./demo.txt")
fmt.Printf("err: %v\n", err)
}
函数功能 : 删除云文件及本地文件
返回格式 : error
package main
import (
"fmt"
"github.com/cnlesscode/gotool/cloud/static"
)
func main() {
staticCloudConfig := &static.Config{
Type: "TencentCOS",
Endpoint: "https://test-***.cos.ap-nanjing.myqcloud.com",
KeyId: "***",
Secret: "***",
BaseUrl: "https://test-***.cos.ap-nanjing.myqcloud.com",
}
err := static.RemoveFile(staticCloudConfig, "demo.txt", false)
fmt.Printf("err: %v\n", err)
}