2018-02-05 16:05:59 -05:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2016-10-06 10:09:54 -04:00
|
|
|
|
2016-11-02 20:43:32 -04:00
|
|
|
import (
|
2017-08-11 13:47:02 -04:00
|
|
|
"path"
|
|
|
|
|
2016-11-02 20:43:32 -04:00
|
|
|
"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-08-11 13:47:02 -04:00
|
|
|
req, err := cli.buildRequest("GET", path.Join(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-09-08 12:04:34 -04:00
|
|
|
return ping, cli.checkResponseErr(serverResp)
|
2016-10-06 10:09:54 -04:00
|
|
|
}
|