-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi_ping.go
More file actions
47 lines (38 loc) · 888 Bytes
/
api_ping.go
File metadata and controls
47 lines (38 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package seafile
import (
"fmt"
"io/ioutil"
"net/http"
)
//测试Seafile服务连通性
func (cli *Client) Ping() error {
resp, err := http.Get(cli.Addr + "/api2/ping")
if err != nil {
return fmt.Errorf("请求错误:%s", err)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("读取错误:%s", err)
}
if string(b) == `"pong"` {
return nil
}
return fmt.Errorf("未知返回:%s", err)
}
//自动添加Token后执行请求
func (cli *Client) AuthPing() error {
resp, err := cli.doRequest("GET", "/auth/ping/", nil, nil)
if err != nil {
return fmt.Errorf("请求错误:%s", err)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("读取错误:%s %s", resp.Status, err)
}
if string(b) == `"pong"` {
return nil
}
return fmt.Errorf("未知返回:%s", err)
}