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"
|
|
|
|
)
|
|
|
|
|
2016-12-19 01:45:48 -05:00
|
|
|
// Ping pings the server and returns the value of the "Docker-Experimental" & "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
|
|
|
}
|
|
|
|
|
2016-11-02 20:43:32 -04:00
|
|
|
return ping, nil
|
2016-10-06 10:09:54 -04:00
|
|
|
}
|