-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create go.yml go upgrade version go-version to 1.23 upload bin,use ubuntu20 add linux arm64
- Loading branch information
Showing
11 changed files
with
565 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: "1.23" | ||
|
||
- name: Build | ||
run: go build -v -o output/go_webdav_client ./... | ||
|
||
- name: Build arm64 | ||
run: export GOOS=linux; export GOARCH=arm64; go build -v -o output/go_webdav_client_arm64 ./... | ||
|
||
- name: Upload build artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: go_webdav_client-build | ||
path: output/go_webdav_client* # 指定要上传的编译文件路径 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
testfile | ||
go_webdav_client | ||
go_webdav_client_arm64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[中文](./Readme_zh.md) | ||
|
||
## WebDAV Client | ||
|
||
### Compiled Binary | ||
|
||
### Tool Usage Screenshot | ||
|
||
![](./doc/usage.png) | ||
|
||
``` | ||
./go_webdav_client init -u https://192.168.31.175 | ||
./go_webdav_client list -w / | ||
``` | ||
|
||
## License and Agreement | ||
|
||
The `go_webdav_client` project is open-sourced under the GPL-3.0 license. Copyright for the project is held by its founder and developer, xtccc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
## webdav客户端工具 | ||
|
||
|
||
### 编译好的二进制 | ||
|
||
|
||
### 工具的使用截图 | ||
|
||
![](./doc/使用.png) | ||
|
||
``` | ||
./go_webdav_client init -u https://192.168.31.175 | ||
./go_webdav_client list -w / | ||
``` | ||
|
||
## 版权和协议 | ||
|
||
go_webdav_client 项目基于 GPL-3.0 开源协议开放项目源代码。本项目版权由项目发起人、开发者xtccc所有。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
linux(){ | ||
rm -f go_webdav_client | ||
go build -o doc/go_webdav_client . | ||
if [ $? = 0 ] ;then | ||
./go_webdav_client upload -f ./go_webdav_client -w /go_webdav_client_test | ||
sudo cp go_webdav_client /usr/local/bin/go_webdav_client | ||
else | ||
echo "build error" | ||
fi | ||
} | ||
|
||
|
||
|
||
# https://192.168.31.175/go_webdav_client_test/ | ||
|
||
|
||
|
||
android(){ | ||
export GOOS=linux | ||
export GOARCH=arm64 | ||
go build -o doc/go_webdav_client_arm64 . && ./go_webdav_client upload -f ./go_webdav_client_arm64 -w /go_webdav_client_test | ||
unset GOOS | ||
unset GOARCH | ||
} | ||
|
||
function usage(){ | ||
echo "all to upload all" | ||
echo "两个参数: linux android " | ||
} | ||
case $1 in | ||
linux) | ||
linux;; | ||
android) | ||
android;; | ||
all) | ||
linux && android ;; | ||
*) | ||
usage;; | ||
esac |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module go_webdav_client | ||
|
||
go 1.23 | ||
|
||
require ( | ||
github.com/jedib0t/go-pretty v4.3.0+incompatible | ||
github.com/schollz/progressbar/v3 v3.16.1 | ||
github.com/spf13/cobra v1.8.1 | ||
github.com/studio-b12/gowebdav v0.9.0 | ||
) | ||
|
||
require ( | ||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect | ||
github.com/go-openapi/errors v0.22.0 // indirect | ||
github.com/go-openapi/strfmt v0.23.0 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/mattn/go-runewidth v0.0.16 // indirect | ||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/oklog/ulid v1.3.1 // indirect | ||
github.com/rivo/uniseg v0.4.7 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
go.mongodb.org/mongo-driver v1.14.0 // indirect | ||
golang.org/x/net v0.30.0 // indirect | ||
golang.org/x/sys v0.26.0 // indirect | ||
golang.org/x/term v0.25.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= | ||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= | ||
github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM= | ||
github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/go-openapi/errors v0.22.0 h1:c4xY/OLxUBSTiepAg3j/MHuAv5mJhnf53LLMWFB+u/w= | ||
github.com/go-openapi/errors v0.22.0/go.mod h1:J3DmZScxCDufmIMsdOuDHxJbdOGC0xtUynjIx092vXE= | ||
github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c= | ||
github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4= | ||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= | ||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= | ||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
github.com/jedib0t/go-pretty v4.3.0+incompatible h1:CGs8AVhEKg/n9YbUenWmNStRW2PHJzaeDodcfvRAbIo= | ||
github.com/jedib0t/go-pretty v4.3.0+incompatible/go.mod h1:XemHduiw8R651AF9Pt4FwCTKeG3oo7hrHJAoznj9nag= | ||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= | ||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= | ||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= | ||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= | ||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= | ||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= | ||
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= | ||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= | ||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= | ||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/schollz/progressbar/v3 v3.16.1 h1:RnF1neWZFzLCoGx8yp1yF7SDl4AzNDI5y4I0aUJRrZQ= | ||
github.com/schollz/progressbar/v3 v3.16.1/go.mod h1:I2ILR76gz5VXqYMIY/LdLecvMHDPVcQm3W/MSKi1TME= | ||
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= | ||
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= | ||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||
github.com/studio-b12/gowebdav v0.9.0 h1:1j1sc9gQnNxbXXM4M/CebPOX4aXYtr7MojAVcN4dHjU= | ||
github.com/studio-b12/gowebdav v0.9.0/go.mod h1:bHA7t77X/QFExdeAnDzK6vKM34kEZAcE1OX4MfiwjkE= | ||
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80= | ||
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= | ||
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= | ||
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= | ||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= | ||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= | ||
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/studio-b12/gowebdav" | ||
) | ||
|
||
func webdav_init() *gowebdav.Client { | ||
root, err := get_url() | ||
if errors.Is(err, os.ErrNotExist) { | ||
fmt.Println("请使用init 命令初始化配置url") | ||
os.Exit(1) | ||
} | ||
user := "user" | ||
password := "password" | ||
|
||
c := gowebdav.NewClient(root, user, password) | ||
tr := &http.Transport{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // 跳过证书验证 | ||
} | ||
|
||
c.SetTransport(tr) | ||
err = c.Connect() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
return c | ||
|
||
} | ||
func main() { | ||
|
||
var rootCmd = &cobra.Command{ | ||
//是命令的名称 | ||
Use: "go_webdave", | ||
//表示当前命令的完整描述。 | ||
Long: "go_webdave 是一个上传下载工具", | ||
|
||
//Run属性是一个函数,当执行命令时会调用此函数。 | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cmd.Help() | ||
}, | ||
} | ||
|
||
var uploadCmd = &cobra.Command{ | ||
Use: "upload", | ||
Short: "上传文件", | ||
Long: "上传文件 需要两个参数:本地文件路径 和 webdav文件路径", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
//通过cmd.flag 获取解析后的flag的值 | ||
webdavFilePath, _ := cmd.Flags().GetString("webdav文件路径") | ||
localFilePath, _ := cmd.Flags().GetString("本地文件路径") | ||
c := webdav_init() | ||
upload(c, localFilePath, webdavFilePath) | ||
|
||
}, | ||
} | ||
|
||
var listCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "列出文件", | ||
Long: "列出文件及目录", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
webdavFilePath, _ := cmd.Flags().GetString("webdav文件路径") | ||
c := webdav_init() | ||
listfile(c, webdavFilePath) | ||
}, | ||
} | ||
|
||
var delCmd = &cobra.Command{ | ||
Use: "del", | ||
Short: "删除文件", | ||
Long: "删除文件", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
webdavFilePath, _ := cmd.Flags().GetString("webdav文件路径") | ||
c := webdav_init() | ||
delete(c, webdavFilePath) | ||
}, | ||
} | ||
|
||
var mkdirCmd = &cobra.Command{ | ||
Use: "mkdir", | ||
Short: "建立文件夹", | ||
Long: "建立文件夹 支持多层建立", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
webdavFilePath, _ := cmd.Flags().GetString("webdav文件路径") | ||
c := webdav_init() | ||
mkdir(c, webdavFilePath) | ||
}, | ||
} | ||
|
||
var downCmd = &cobra.Command{ | ||
Use: "download", | ||
Short: "下载文件", | ||
Long: "下载文件", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
webdavFilePath, _ := cmd.Flags().GetString("webdav文件路径") | ||
localFilePath, _ := cmd.Flags().GetString("本地文件路径") | ||
c := webdav_init() | ||
download(c, webdavFilePath, localFilePath) | ||
}, | ||
} | ||
var init_url = &cobra.Command{ | ||
Use: "init", | ||
Short: "初始化url配置", | ||
Long: "初始化url配置", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
url, _ := cmd.Flags().GetString("访问的url") | ||
init_url(url) | ||
}, | ||
} | ||
|
||
var localFilePath string | ||
var webdavFilePath string | ||
|
||
//添加子命令 upload | ||
rootCmd.AddCommand(uploadCmd) | ||
//添加命令下的flag | ||
uploadCmd.Flags().StringVarP(&localFilePath, "本地文件路径", "f", "/", "本地文件路径") | ||
uploadCmd.MarkFlagRequired("本地文件路径") | ||
|
||
uploadCmd.Flags().StringVarP(&webdavFilePath, "webdav文件路径", "w", "/", "webdave文件路径") | ||
uploadCmd.MarkFlagRequired("webdav文件路径") | ||
uploadCmd.Flags().SortFlags = false | ||
|
||
//添加子命令 list | ||
rootCmd.AddCommand(listCmd) | ||
listCmd.Flags().StringVarP(&webdavFilePath, "webdav文件路径", "w", "/", "webdave文件路径") | ||
listCmd.MarkFlagRequired("webdav文件路径") | ||
listCmd.Flags().SortFlags = false | ||
|
||
//添加子命令 del | ||
rootCmd.AddCommand(delCmd) | ||
delCmd.Flags().StringVarP(&webdavFilePath, "webdav文件路径", "w", "", "webdave文件路径") | ||
delCmd.MarkFlagRequired("webdav文件路径") | ||
delCmd.Flags().SortFlags = false | ||
|
||
rootCmd.AddCommand(mkdirCmd) | ||
mkdirCmd.Flags().StringVarP(&webdavFilePath, "webdav文件路径", "w", "", "webdave文件路径") | ||
mkdirCmd.MarkFlagRequired("webdav文件路径") | ||
mkdirCmd.Flags().SortFlags = false | ||
|
||
//添加子命令 upload | ||
rootCmd.AddCommand(downCmd) | ||
//添加命令下的flag | ||
downCmd.Flags().StringVarP(&webdavFilePath, "webdav文件路径", "w", "/", "webdave文件路径") | ||
downCmd.MarkFlagRequired("webdav文件路径") | ||
downCmd.Flags().StringVarP(&localFilePath, "本地文件路径", "f", "/", "本地文件路径") | ||
downCmd.MarkFlagRequired("本地文件路径") | ||
downCmd.Flags().SortFlags = false | ||
|
||
rootCmd.AddCommand(init_url) | ||
var url string | ||
init_url.Flags().StringVarP(&url, "访问的url", "u", "https://192.168.31.175", "访问的url") | ||
|
||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} |
Oops, something went wrong.