1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-07 14:12:28 +08:00

doc: add document for DownloadFile and UploadFile

This commit is contained in:
dudaodong
2023-04-19 16:16:47 +08:00
parent 6d5ec807f7
commit 05997603a9
3 changed files with 121 additions and 12 deletions

View File

@@ -44,6 +44,8 @@ import (
- [HttpPut<sup>Deprecated</sup>](#HttpPut)
- [HttpPatch<sup>Deprecated</sup>](#HttpPatch)
- [ParseHttpResponse](#ParseHttpResponse)
- [DownloadFile](#DownloadFile)
- [UploadFile](#UploadFile)
- [IsPingConnected](#IsPingConnected)
- [IsTelnetConnected](#IsTelnetConnected)
@@ -899,6 +901,61 @@ func main() {
}
```
### <span id="DownloadFile">DownloadFile</span>
<p>Download the file exist in url to a local file.</p>
<b>Signature:</b>
```go
func DownloadFile(filepath string, url string) error
```
<b>Example:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/netutil"
)
func main() {
err := DownloadFile("./lancet_logo.jpg", "https://picx.zhimg.com/v2-fc82a4199749de9cfb71e32e54f489d3_720w.jpg?source=172ae18b")
fmt.Println(err)
}
```
### <span id="UploadFile">UploadFile</span>
<p>Upload the file to a server.</p>
<b>Signature:</b>
```go
func UploadFile(filepath string, server string) (bool, error)
```
<b>Example:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/netutil"
)
func main() {
ok, err := netutil.UploadFile("./a.jpg", "http://www.xxx.com/bucket/test")
fmt.Println(ok)
fmt.Println(err)
}
```
### <span id="IsPingConnected">IsPingConnected</span>
<p>checks if can ping the specified host or not.</p>
@@ -915,10 +972,7 @@ func IsPingConnected(host string) bool
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"github.com/duke-git/lancet/v2/netutil"
)
@@ -951,10 +1005,7 @@ func IsTelnetConnected(host string, port string) bool
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"github.com/duke-git/lancet/v2/netutil"
)

View File

@@ -44,6 +44,8 @@ import (
- [HttpPut<sup>Deprecated</sup>](#HttpPut)
- [HttpPatch<sup>Deprecated</sup>](#HttpPatch)
- [ParseHttpResponse](#ParseHttpResponse)
- [DownloadFile](#DownloadFile)
- [UploadFile](#UploadFile)
- [IsPingConnected](#IsPingConnected)
- [IsTelnetConnected](#IsTelnetConnected)
@@ -901,6 +903,61 @@ func main() {
}
```
### <span id="DownloadFile">DownloadFile</span>
<p>从指定的server地址下载文件。</p>
<b>函数签名:</b>
```go
func DownloadFile(filepath string, url string) error
```
<b>示例:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/netutil"
)
func main() {
err := DownloadFile("./lancet_logo.jpg", "https://picx.zhimg.com/v2-fc82a4199749de9cfb71e32e54f489d3_720w.jpg?source=172ae18b")
fmt.Println(err)
}
```
### <span id="UploadFile">UploadFile</span>
<p>将文件上传指定的server地址。</p>
<b>函数签名:</b>
```go
func UploadFile(filepath string, server string) (bool, error)
```
<b>示例:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/netutil"
)
func main() {
ok, err := netutil.UploadFile("./a.jpg", "http://www.xxx.com/bucket/test")
fmt.Println(ok)
fmt.Println(err)
}
```
### <span id="IsPingConnected">IsPingConnected</span>
<p>检查能否ping通主机。</p>
@@ -917,10 +974,7 @@ func IsPingConnected(host string) bool
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"github.com/duke-git/lancet/v2/netutil"
)
@@ -953,10 +1007,7 @@ func IsTelnetConnected(host string, port string) bool
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"github.com/duke-git/lancet/v2/netutil"
)

View File

@@ -110,6 +110,13 @@ func TestEncodeUrl(t *testing.T) {
assert.Equal(expected, encodedUrl)
}
// func TestDownloadFile(t *testing.T) {
// assert := internal.NewAssert(t, "TestDownloadFile")
// err := DownloadFile("./lancet_logo.jpg", "https://picx.zhimg.com/v2-fc82a4199749de9cfb71e32e54f489d3_720w.jpg?source=172ae18b")
// assert.IsNil(err)
// }
func TestIsPingConnected(t *testing.T) {
assert := internal.NewAssert(t, "TestIsPingConnected")