version.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package lib
  2. import (
  3. "encoding/json"
  4. "runtime"
  5. "github.com/docker/docker/api"
  6. "github.com/docker/docker/api/types"
  7. "github.com/docker/docker/dockerversion"
  8. "github.com/docker/docker/utils"
  9. )
  10. // VersionResponse holds version information for the client and the server
  11. type VersionResponse struct {
  12. Client *types.Version
  13. Server *types.Version
  14. }
  15. // ServerOK return true when the client could connect to the docker server
  16. // and parse the information received. It returns false otherwise.
  17. func (v VersionResponse) ServerOK() bool {
  18. return v.Server == nil
  19. }
  20. // SystemVersion returns information of the docker client and server host.
  21. func (cli *Client) SystemVersion() (VersionResponse, error) {
  22. client := &types.Version{
  23. Version: dockerversion.Version,
  24. APIVersion: api.Version,
  25. GoVersion: runtime.Version(),
  26. GitCommit: dockerversion.GitCommit,
  27. BuildTime: dockerversion.BuildTime,
  28. Os: runtime.GOOS,
  29. Arch: runtime.GOARCH,
  30. Experimental: utils.ExperimentalBuild(),
  31. }
  32. resp, err := cli.GET("/version", nil, nil)
  33. if err != nil {
  34. return VersionResponse{Client: client}, err
  35. }
  36. defer ensureReaderClosed(resp)
  37. var server types.Version
  38. err = json.NewDecoder(resp.body).Decode(&server)
  39. if err != nil {
  40. return VersionResponse{Client: client}, err
  41. }
  42. return types.VersionResponse{Client: client, Server: &server}, nil
  43. }