2016-10-06 10:09:54 -04:00
|
|
|
package client
|
|
|
|
|
2016-11-02 20:43:32 -04:00
|
|
|
import (
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
2017-02-07 07:52:20 -05:00
|
|
|
// Ping pings the server and returns the value of the "Docker-Experimental", "OS-Type" & "API-Version" headers
|
2016-11-02 20:43:32 -04:00
|
|
|
func (cli *Client) Ping(ctx context.Context) (types.Ping, error) {
|
|
|
|
var ping types.Ping
|
2017-06-02 08:00:56 -04:00
|
|
|
req, err := cli.buildRequest("GET", cli.basePath+"/_ping", nil, nil)
|
2016-11-02 20:43:32 -04:00
|
|
|
if err != nil {
|
|
|
|
return ping, err
|
|
|
|
}
|
|
|
|
serverResp, err := cli.doRequest(ctx, req)
|
2016-10-06 10:09:54 -04:00
|
|
|
if err != nil {
|
2016-11-02 20:43:32 -04:00
|
|
|
return ping, err
|
2016-10-06 10:09:54 -04:00
|
|
|
}
|
|
|
|
defer ensureReaderClosed(serverResp)
|
|
|
|
|
2017-06-26 12:06:34 -04:00
|
|
|
if serverResp.header != nil {
|
|
|
|
ping.APIVersion = serverResp.header.Get("API-Version")
|
2016-11-02 20:43:32 -04:00
|
|
|
|
2017-06-26 12:06:34 -04:00
|
|
|
if serverResp.header.Get("Docker-Experimental") == "true" {
|
|
|
|
ping.Experimental = true
|
|
|
|
}
|
|
|
|
ping.OSType = serverResp.header.Get("OSType")
|
2016-10-06 10:09:54 -04:00
|
|
|
}
|
|
|
|
|
2017-06-26 12:06:34 -04:00
|
|
|
err = cli.checkResponseErr(serverResp)
|
|
|
|
return ping, err
|
2016-10-06 10:09:54 -04:00
|
|
|
}
|