本文整理匯總了Golang中github.com/docker/docker/cli/command.DockerCli.DefaultVersion方法的典型用法代碼示例。如果您正苦於以下問題:Golang DockerCli.DefaultVersion方法的具體用法?Golang DockerCli.DefaultVersion怎麽用?Golang DockerCli.DefaultVersion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/docker/cli/command.DockerCli
的用法示例。
在下文中一共展示了DockerCli.DefaultVersion方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runVersion
func runVersion(dockerCli *command.DockerCli, opts *versionOptions) error {
ctx := context.Background()
templateFormat := versionTemplate
if opts.format != "" {
templateFormat = opts.format
}
tmpl, err := templates.Parse(templateFormat)
if err != nil {
return cli.StatusError{StatusCode: 64,
Status: "Template parsing error: " + err.Error()}
}
APIVersion := dockerCli.Client().ClientVersion()
if defaultAPIVersion := dockerCli.DefaultVersion(); APIVersion != defaultAPIVersion {
APIVersion = fmt.Sprintf("%s (downgraded from %s)", APIVersion, defaultAPIVersion)
}
vd := types.VersionResponse{
Client: &types.Version{
Version: dockerversion.Version,
APIVersion: APIVersion,
GoVersion: runtime.Version(),
GitCommit: dockerversion.GitCommit,
BuildTime: dockerversion.BuildTime,
Os: runtime.GOOS,
Arch: runtime.GOARCH,
},
}
serverVersion, err := dockerCli.Client().ServerVersion(ctx)
if err == nil {
vd.Server = &serverVersion
}
// first we need to make BuildTime more human friendly
t, errTime := time.Parse(time.RFC3339Nano, vd.Client.BuildTime)
if errTime == nil {
vd.Client.BuildTime = t.Format(time.ANSIC)
}
if vd.ServerOK() {
t, errTime = time.Parse(time.RFC3339Nano, vd.Server.BuildTime)
if errTime == nil {
vd.Server.BuildTime = t.Format(time.ANSIC)
}
}
if err2 := tmpl.Execute(dockerCli.Out(), vd); err2 != nil && err == nil {
err = err2
}
dockerCli.Out().Write([]byte{'\n'})
return err
}