mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-17 11:12:28 +08:00
doc: add document for DownloadFile and UploadFile
This commit is contained in:
@@ -44,6 +44,8 @@ import (
|
|||||||
- [HttpPut<sup>Deprecated</sup>](#HttpPut)
|
- [HttpPut<sup>Deprecated</sup>](#HttpPut)
|
||||||
- [HttpPatch<sup>Deprecated</sup>](#HttpPatch)
|
- [HttpPatch<sup>Deprecated</sup>](#HttpPatch)
|
||||||
- [ParseHttpResponse](#ParseHttpResponse)
|
- [ParseHttpResponse](#ParseHttpResponse)
|
||||||
|
- [DownloadFile](#DownloadFile)
|
||||||
|
- [UploadFile](#UploadFile)
|
||||||
- [IsPingConnected](#IsPingConnected)
|
- [IsPingConnected](#IsPingConnected)
|
||||||
- [IsTelnetConnected](#IsTelnetConnected)
|
- [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>
|
### <span id="IsPingConnected">IsPingConnected</span>
|
||||||
|
|
||||||
<p>checks if can ping the specified host or not.</p>
|
<p>checks if can ping the specified host or not.</p>
|
||||||
@@ -915,10 +972,7 @@ func IsPingConnected(host string) bool
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"github.com/duke-git/lancet/v2/netutil"
|
"github.com/duke-git/lancet/v2/netutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -951,10 +1005,7 @@ func IsTelnetConnected(host string, port string) bool
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"github.com/duke-git/lancet/v2/netutil"
|
"github.com/duke-git/lancet/v2/netutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ import (
|
|||||||
- [HttpPut<sup>Deprecated</sup>](#HttpPut)
|
- [HttpPut<sup>Deprecated</sup>](#HttpPut)
|
||||||
- [HttpPatch<sup>Deprecated</sup>](#HttpPatch)
|
- [HttpPatch<sup>Deprecated</sup>](#HttpPatch)
|
||||||
- [ParseHttpResponse](#ParseHttpResponse)
|
- [ParseHttpResponse](#ParseHttpResponse)
|
||||||
|
- [DownloadFile](#DownloadFile)
|
||||||
|
- [UploadFile](#UploadFile)
|
||||||
- [IsPingConnected](#IsPingConnected)
|
- [IsPingConnected](#IsPingConnected)
|
||||||
- [IsTelnetConnected](#IsTelnetConnected)
|
- [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>
|
### <span id="IsPingConnected">IsPingConnected</span>
|
||||||
|
|
||||||
<p>检查能否ping通主机。</p>
|
<p>检查能否ping通主机。</p>
|
||||||
@@ -917,10 +974,7 @@ func IsPingConnected(host string) bool
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"github.com/duke-git/lancet/v2/netutil"
|
"github.com/duke-git/lancet/v2/netutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -953,10 +1007,7 @@ func IsTelnetConnected(host string, port string) bool
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"github.com/duke-git/lancet/v2/netutil"
|
"github.com/duke-git/lancet/v2/netutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -110,6 +110,13 @@ func TestEncodeUrl(t *testing.T) {
|
|||||||
assert.Equal(expected, encodedUrl)
|
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) {
|
func TestIsPingConnected(t *testing.T) {
|
||||||
assert := internal.NewAssert(t, "TestIsPingConnected")
|
assert := internal.NewAssert(t, "TestIsPingConnected")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user