2016-10-06 10:09:54 -04:00
|
|
|
package client
|
|
|
|
|
2016-11-02 20:43:32 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
2016-10-06 10:09:54 -04:00
|
|
|
|
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
|
|
|
|
req, err := cli.buildRequest("GET", fmt.Sprintf("%s/_ping", cli.basePath), nil, nil)
|
|
|
|
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)
|
|
|
|
|
2016-11-02 20:43:32 -04:00
|
|
|
ping.APIVersion = serverResp.header.Get("API-Version")
|
|
|
|
|
|
|
|
if serverResp.header.Get("Docker-Experimental") == "true" {
|
|
|
|
ping.Experimental = true
|
2016-10-06 10:09:54 -04:00
|
|
|
}
|
|
|
|
|
2017-02-07 07:52:20 -05:00
|
|
|
ping.OSType = serverResp.header.Get("OSType")
|
|
|
|
|
2016-11-02 20:43:32 -04:00
|
|
|
return ping, nil
|
2016-10-06 10:09:54 -04:00
|
|
|
}
|