基于 Go 语言开发的 天翼云 对象存储(经典版)I型 脚手架
为简化开发工作、提高生产率、解决常见问题而生
- Windows/Linux/Mac、x86/arm 可执行程序:https://github.com/xuxiaowei-com-cn/ct-oos-go/releases
go env -w GOPROXY=https://goproxy.cn,direct
# go env -w GOPROXY=https://mirrors.aliyun.com/goproxy,direct
go get -u github.com/urfave/cli/v2
go get -u github.com/xuxiaowei-com-cn/ct-oos-go-sdk
go get -u github.com/xuxiaowei-com-cn/git-go@main
go get -u gopkg.in/yaml.v3
go mod tidy
go mod download
go run main.go
- Windows 环境为 %xxx%
- Linux 环境为 $xxx
go run main.go --help
$ go run main.go --help
NAME:
ct-oos-go - 基于 Go 语言开发的 天翼云 对象存储(经典版)I型 命令行工具
USAGE:
ct-oos-go [global options] command [command options] [arguments...]
VERSION:
dev
AUTHOR:
徐晓伟 <[email protected]>
COMMANDS:
bucket 桶
put 上传对象
upload 上传文件-分片
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
COPYRIGHT:
徐晓伟工作室 <[email protected]>
-
bucket
$ go run main.go bucket --help NAME: ct-oos-go bucket - 桶 USAGE: ct-oos-go bucket command [command options] [arguments...] COMMANDS: get-location 获取 location bucket help, h Shows a list of commands or help for one command OPTIONS: --access-key value 天翼云 AccessKey [%CT_OOS_ACCESS_KEY%] --secret-key value 天翼云 SecretKey [%CT_OOS_SECRET_KEY%] --endpoint value 天翼云 Endpoint [%CT_OOS_ENDPOINT%] --bucket-name value, --bucket value 天翼云 bucketName [%CT_OOS_BUCKET_NAME%] --enable-log 开启日志 (default: false) --log-name value 日志名称-前缀 (default: "ct-oos-go") --log-folder value 日志文件夹,默认是当前用户主目录下的 .ct-oos-go 文件夹 --connect-timeout-sec value 连接超时时间,单位是 s (default: 3) --read-write-timeout-sec value 读写超时时间,单位是 s (default: 3) --microseconds 日志打印时间精确到微秒 (default: false) --long-file 日志打印使用长包名 (default: false) --help, -h show help
-
put
$ go run main.go put --help NAME: ct-oos-go put - 上传对象 USAGE: ct-oos-go put command [command options] [arguments...] COMMANDS: string 上传 字符串 file 上传 文件 folder 上传 文件夹 help, h Shows a list of commands or help for one command OPTIONS: --access-key value 天翼云 AccessKey [%CT_OOS_ACCESS_KEY%] --secret-key value 天翼云 SecretKey [%CT_OOS_SECRET_KEY%] --endpoint value 天翼云 Endpoint [%CT_OOS_ENDPOINT%] --bucket-name value, --bucket value 天翼云 bucketName [%CT_OOS_BUCKET_NAME%] --uri value 上传路径-URI --string value 上传字符串 --file value 上传文件 --folder value 上传文件夹 --force 是否强制上传,会覆盖文件 (default: false) --enable-log 开启日志 (default: false) --log-name value 日志名称-前缀 (default: "ct-oos-go") --log-folder value 日志文件夹,默认是当前用户主目录下的 .ct-oos-go 文件夹 --connect-timeout-sec value 连接超时时间,单位是 s (default: 3) --read-write-timeout-sec value 读写超时时间,单位是 s (default: 3) --microseconds 日志打印时间精确到微秒 (default: false) --long-file 日志打印使用长包名 (default: false) --help, -h show help
-
upload
$ go run main.go upload --help NAME: ct-oos-go upload - 上传文件-分片 USAGE: ct-oos-go upload command [command options] [arguments...] COMMANDS: file 上传 文件-分片 folder 上传 文件夹-分片 help, h Shows a list of commands or help for one command OPTIONS: --access-key value 天翼云 AccessKey [%CT_OOS_ACCESS_KEY%] --secret-key value 天翼云 SecretKey [%CT_OOS_SECRET_KEY%] --endpoint value 天翼云 Endpoint [%CT_OOS_ENDPOINT%] --bucket-name value, --bucket value 天翼云 bucketName [%CT_OOS_BUCKET_NAME%] --uri value 上传路径-URI --file value 上传文件 --folder value 上传文件夹 --part-size value 文件分片大小,单位 M,最小值 5 M,分片数量不能超过 10000 (default: 5) --routine value 线程 (default: 3) --force 是否强制上传,会覆盖文件 (default: false) --enable-log 开启日志 (default: false) --log-name value 日志名称-前缀 (default: "ct-oos-go") --log-folder value 日志文件夹,默认是当前用户主目录下的 .ct-oos-go 文件夹 --connect-timeout-sec value 连接超时时间,单位是 s (default: 3) --read-write-timeout-sec value 读写超时时间,单位是 s (default: 3) --microseconds 日志打印时间精确到微秒 (default: false) --long-file 日志打印使用长包名 (default: false) --help, -h show help
go test ./... -v
go build
# GOOS=:设置构建的目标操作系统(darwin | freebsd | linux | windows)
# GOARCH=:设置构建的目标操作系统(386 | amd64 | arm | arm64)
# -v:打印编译过程中的详细信息
# -ldflags:设置在编译时传递给链接器的参数
# -ldflags "-s -w -buildid="
# -s: 删除符号表信息,减小可执行文件的大小。
# -w: 删除调试信息,使可执行文件在运行时不会打印调试信息。
# -buildid=: 删除构建ID,使可执行文件在运行时不会打印构建ID。
# -trimpath:去掉所有包含 go path 的路径
# -o:指定构建后输出的文件名
-
Windows
- amd64
go build -o buildinfo/buildinfo.exe buildinfo/buildinfo.go GOOS=windows GOARCH=amd64 go build -v -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo.exe now) -X main.Compiler= -X main.GitCommitBranch=$(buildinfo/buildinfo.exe commitBranch) -X main.GitCommitSha=$(buildinfo/buildinfo.exe commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo.exe commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo.exe commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo.exe commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo.exe git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo.exe commitTag) -X main.GoVersion=$(buildinfo/buildinfo.exe goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=windows/amd64 -X main.CiPipelineId= -X main.CiJobId=" -trimpath -o ct-oos-go-windows-amd64.exe .
- arm64
go build -o buildinfo/buildinfo.exe buildinfo/buildinfo.go GOOS=windows GOARCH=arm64 go build -v -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo.exe now) -X main.Compiler= -X main.GitCommitBranch=$(buildinfo/buildinfo.exe commitBranch) -X main.GitCommitSha=$(buildinfo/buildinfo.exe commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo.exe commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo.exe commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo.exe commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo.exe git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo.exe commitTag) -X main.GoVersion=$(buildinfo/buildinfo.exe goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=windows/arm64 -X main.CiPipelineId= -X main.CiJobId=" -trimpath -o ct-oos-go-windows-arm64.exe .
- amd64
-
Linux
- amd64
go build -o buildinfo/buildinfo buildinfo/buildinfo.go GOOS=linux GOARCH=amd64 go build -v -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo now) -X main.Compiler= -X main.GitCommitBranch=$(buildinfo/buildinfo commitBranch) -X main.GitCommitSha=$(buildinfo/buildinfo commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo commitTag) -X main.GoVersion=$(buildinfo/buildinfo goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=linux/amd64 -X main.CiPipelineId= -X main.CiJobId=" -trimpath -o ct-oos-go-linux-amd64 .
- arm64
go build -o buildinfo/buildinfo buildinfo/buildinfo.go GOOS=linux GOARCH=arm64 go build -v -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo now) -X main.Compiler= -X main.GitCommitBranch=$(buildinfo/buildinfo commitBranch) -X main.GitCommitSha=$(buildinfo/buildinfo commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo commitTag) -X main.GoVersion=$(buildinfo/buildinfo goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=linux/arm64 -X main.CiPipelineId= -X main.CiJobId=" -trimpath -o ct-oos-go-linux-arm64 .
- amd64
-
Darwin
- amd64
go build -o buildinfo/buildinfo buildinfo/buildinfo.go GOOS=darwin GOARCH=amd64 go build -v -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo now) -X main.Compiler= -X main.GitCommitBranch=$(buildinfo/buildinfo commitBranch) -X main.GitCommitSha=$(buildinfo/buildinfo commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo commitTag) -X main.GoVersion=$(buildinfo/buildinfo goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=darwin/amd64 -X main.CiPipelineId= -X main.CiJobId=" -trimpath -o ct-oos-go-darwin-amd64 .
- arm64
go build -o buildinfo/buildinfo buildinfo/buildinfo.go GOOS=darwin GOARCH=arm64 go build -v -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo now) -X main.Compiler= -X main.GitCommitBranch=$(buildinfo/buildinfo commitBranch) -X main.GitCommitSha=$(buildinfo/buildinfo commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo commitTag) -X main.GoVersion=$(buildinfo/buildinfo goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=darwin/arm64 -X main.CiPipelineId= -X main.CiJobId=" -trimpath -o ct-oos-go-darwin-arm64 .
- amd64