1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/api/client/lib/version.go
David Calavera 1fe912151b Implement docker version with standalone client lib.
Use Go template definitions for default format.

Signed-off-by: David Calavera <david.calavera@gmail.com>
2015-12-09 12:04:58 -05:00

50 lines
1.3 KiB
Go

package lib
import (
"encoding/json"
"runtime"
"github.com/docker/docker/api"
"github.com/docker/docker/api/types"
"github.com/docker/docker/dockerversion"
"github.com/docker/docker/utils"
)
// VersionResponse holds version information for the client and the server
type VersionResponse struct {
Client *types.Version
Server *types.Version
}
// ServerOK return true when the client could connect to the docker server
// and parse the information received. It returns false otherwise.
func (v VersionResponse) ServerOK() bool {
return v.Server == nil
}
// SystemVersion returns information of the docker client and server host.
func (cli *Client) SystemVersion() (VersionResponse, error) {
client := &types.Version{
Version: dockerversion.Version,
APIVersion: api.Version,
GoVersion: runtime.Version(),
GitCommit: dockerversion.GitCommit,
BuildTime: dockerversion.BuildTime,
Os: runtime.GOOS,
Arch: runtime.GOARCH,
Experimental: utils.ExperimentalBuild(),
}
resp, err := cli.GET("/version", nil, nil)
if err != nil {
return VersionResponse{Client: client}, err
}
defer ensureReaderClosed(resp)
var server types.Version
err = json.NewDecoder(resp.body).Decode(&server)
if err != nil {
return VersionResponse{Client: client}, err
}
return types.VersionResponse{Client: client, Server: &server}, nil
}