mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-09 07:02:29 +08:00
doc: add play ground demo
This commit is contained in:
@@ -843,7 +843,7 @@ func main() {
|
||||
|
||||
### <span id="ReadFile">ReadFile</span>
|
||||
|
||||
<p>读取文件或者URL</p>
|
||||
<p>读取文件或者URL。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
@@ -851,7 +851,7 @@ func main() {
|
||||
func ReadFile(path string) (reader io.ReadCloser, closeFn func(), err error)
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;"></span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/uNep3Tr8fqF)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -862,19 +862,19 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
reader, fn, err := ReadFile("https://httpbin.org/robots.txt")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer fn()
|
||||
reader, fn, err := fileutil.ReadFile("https://httpbin.org/robots.txt")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer fn()
|
||||
|
||||
dat, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println(string(dat))
|
||||
// Output:
|
||||
// User-agent: *
|
||||
// Disallow: /deny
|
||||
dat, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println(string(dat))
|
||||
// Output:
|
||||
// User-agent: *
|
||||
// Disallow: /deny
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user