本文整理汇总了Golang中github.com/docker/go-units.HumanDuration函数的典型用法代码示例。如果您正苦于以下问题:Golang HumanDuration函数的具体用法?Golang HumanDuration怎么用?Golang HumanDuration使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HumanDuration函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: status
func status(container *docker.Container, config *api.MasterConfig) string {
mountMap := make(map[string]string)
for _, mount := range container.Mounts {
mountMap[mount.Destination] = mount.Source
}
duration := strings.ToLower(units.HumanDuration(time.Now().Sub(container.State.StartedAt)))
status := fmt.Sprintf("The OpenShift cluster was started %s ago\n\n", duration)
status = status + fmt.Sprintf("Web console URL: %s\n", config.AssetConfig.MasterPublicURL)
if config.AssetConfig.MetricsPublicURL != "" {
status = status + fmt.Sprintf("Metrics URL: %s\n", config.AssetConfig.MetricsPublicURL)
}
if config.AssetConfig.LoggingPublicURL != "" {
status = status + fmt.Sprintf("Logging URL: %s\n", config.AssetConfig.LoggingPublicURL)
}
status = status + fmt.Sprintf("\n")
status = status + fmt.Sprintf("Config is at host directory %s\n", mountMap["/var/lib/origin/openshift.local.config"])
status = status + fmt.Sprintf("Volumes are at host directory %s\n", mountMap["/var/lib/origin/openshift.local.volumes"])
if _, hasKey := mountMap["/var/lib/origin/openshift.local.etcd"]; hasKey {
status = status + fmt.Sprintf("Data is at host directory %s\n", mountMap["/var/lib/origin/openshift.local.etcd"])
} else {
status = status + fmt.Sprintf("Data will be discarded when cluster is destroyed\n")
}
return status
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:29,代码来源:status.go
示例2: cancel
// cancel cancels any deployment process in progress for config.
func (o DeployOptions) cancel(config *deployapi.DeploymentConfig) error {
if config.Spec.Paused {
return fmt.Errorf("cannot cancel a paused deployment config")
}
deployments, err := o.kubeClient.ReplicationControllers(config.Namespace).List(kapi.ListOptions{LabelSelector: deployutil.ConfigSelector(config.Name)})
if err != nil {
return err
}
if len(deployments.Items) == 0 {
fmt.Fprintf(o.out, "There have been no deployments for %s/%s\n", config.Namespace, config.Name)
return nil
}
sort.Sort(deployutil.ByLatestVersionDesc(deployments.Items))
failedCancellations := []string{}
anyCancelled := false
for _, deployment := range deployments.Items {
status := deployutil.DeploymentStatusFor(&deployment)
switch status {
case deployapi.DeploymentStatusNew,
deployapi.DeploymentStatusPending,
deployapi.DeploymentStatusRunning:
if deployutil.IsDeploymentCancelled(&deployment) {
continue
}
deployment.Annotations[deployapi.DeploymentCancelledAnnotation] = deployapi.DeploymentCancelledAnnotationValue
deployment.Annotations[deployapi.DeploymentStatusReasonAnnotation] = deployapi.DeploymentCancelledByUser
_, err := o.kubeClient.ReplicationControllers(deployment.Namespace).Update(&deployment)
if err == nil {
fmt.Fprintf(o.out, "Cancelled deployment #%d\n", config.Status.LatestVersion)
anyCancelled = true
} else {
fmt.Fprintf(o.out, "Couldn't cancel deployment #%d (status: %s): %v\n", deployutil.DeploymentVersionFor(&deployment), status, err)
failedCancellations = append(failedCancellations, strconv.FormatInt(deployutil.DeploymentVersionFor(&deployment), 10))
}
}
}
if len(failedCancellations) > 0 {
return fmt.Errorf("couldn't cancel deployment %s", strings.Join(failedCancellations, ", "))
}
if !anyCancelled {
latest := &deployments.Items[0]
maybeCancelling := ""
if deployutil.IsDeploymentCancelled(latest) && !deployutil.IsTerminatedDeployment(latest) {
maybeCancelling = " (cancelling)"
}
timeAt := strings.ToLower(units.HumanDuration(time.Now().Sub(latest.CreationTimestamp.Time)))
fmt.Fprintf(o.out, "No deployments are in progress (latest deployment #%d %s%s %s ago)\n",
deployutil.DeploymentVersionFor(latest),
strings.ToLower(string(deployutil.DeploymentStatusFor(latest))),
maybeCancelling,
timeAt)
}
return nil
}
开发者ID:rootfs,项目名称:origin,代码行数:57,代码来源:deploy.go
示例3: UpdateStatusCompleted
func (ctx *serviceInspectContext) UpdateStatusCompleted() string {
return units.HumanDuration(time.Since(*ctx.Service.UpdateStatus.CompletedAt))
}
开发者ID:docker,项目名称:docker,代码行数:3,代码来源:service.go
示例4: formatImageStreamTags
//.........这里部分代码省略.........
case !hasSpecTag || tagRef.From == nil:
fmt.Fprintf(out, " pushed image\n")
case tagRef.From.Kind == "ImageStreamTag":
switch {
case tagRef.Reference:
fmt.Fprintf(out, " reference to %s\n", name)
case scheduled:
fmt.Fprintf(out, " updates automatically from %s\n", name)
default:
fmt.Fprintf(out, " tagged from %s\n", name)
}
case tagRef.From.Kind == "DockerImage":
switch {
case tagRef.Reference:
fmt.Fprintf(out, " reference to registry %s\n", name)
case scheduled:
fmt.Fprintf(out, " updates automatically from registry %s\n", name)
default:
fmt.Fprintf(out, " tagged from %s\n", name)
}
case tagRef.From.Kind == "ImageStreamImage":
switch {
case tagRef.Reference:
fmt.Fprintf(out, " reference to image %s\n", name)
default:
fmt.Fprintf(out, " tagged from %s\n", name)
}
default:
switch {
case tagRef.Reference:
fmt.Fprintf(out, " reference to %s %s\n", tagRef.From.Kind, name)
default:
fmt.Fprintf(out, " updates from %s %s\n", tagRef.From.Kind, name)
}
}
if insecure {
fmt.Fprintf(out, " will use insecure HTTPS or HTTP connections\n")
}
fmt.Fprintln(out)
extraOutput := false
if d := tagRef.Annotations["description"]; len(d) > 0 {
fmt.Fprintf(out, " %s\n", d)
extraOutput = true
}
if t := tagRef.Annotations["tags"]; len(t) > 0 {
fmt.Fprintf(out, " Tags: %s\n", strings.Join(strings.Split(t, ","), ", "))
extraOutput = true
}
if t := tagRef.Annotations["supports"]; len(t) > 0 {
fmt.Fprintf(out, " Supports: %s\n", strings.Join(strings.Split(t, ","), ", "))
extraOutput = true
}
if t := tagRef.Annotations["sampleRepo"]; len(t) > 0 {
fmt.Fprintf(out, " Example Repo: %s\n", t)
extraOutput = true
}
if extraOutput {
fmt.Fprintln(out)
}
if importing {
fmt.Fprintf(out, " ~ importing latest image ...\n")
}
for i := range taglist.Conditions {
condition := &taglist.Conditions[i]
switch condition.Type {
case imageapi.ImportSuccess:
if condition.Status == api.ConditionFalse {
d := now.Sub(condition.LastTransitionTime.Time)
fmt.Fprintf(out, " ! error: Import failed (%s): %s\n %s ago\n", condition.Reason, condition.Message, units.HumanDuration(d))
}
}
}
if len(taglist.Items) == 0 {
continue
}
for i, event := range taglist.Items {
d := now.Sub(event.Created.Time)
if i == 0 {
fmt.Fprintf(out, " * %s\n", event.DockerImageReference)
} else {
fmt.Fprintf(out, " %s\n", event.DockerImageReference)
}
ref, err := imageapi.ParseDockerImageReference(event.DockerImageReference)
id := event.Image
if len(id) > 0 && err == nil && ref.ID != id {
fmt.Fprintf(out, " %s ago\t%s\n", units.HumanDuration(d), id)
} else {
fmt.Fprintf(out, " %s ago\n", units.HumanDuration(d))
}
}
}
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:101,代码来源:helpers.go
示例5: formatRelativeTime
func formatRelativeTime(t time.Time) string {
return units.HumanDuration(timeNowFn().Sub(t))
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:3,代码来源:helpers.go
示例6: formatToHumanDuration
// Receives a time.Duration and returns Docker go-utils'
// human-readable output
func formatToHumanDuration(dur time.Duration) string {
return units.HumanDuration(dur)
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:5,代码来源:helpers.go
示例7: CreatedSince
func (c *imageContext) CreatedSince() string {
c.AddHeader(createdSinceHeader)
createdAt := time.Unix(int64(c.i.Created), 0)
return units.HumanDuration(time.Now().UTC().Sub(createdAt))
}
开发者ID:Mic92,项目名称:docker,代码行数:5,代码来源:image.go
示例8: RunningFor
func (c *containerContext) RunningFor() string {
c.AddHeader(runningForHeader)
createdAt := time.Unix(int64(c.c.Created), 0)
return units.HumanDuration(time.Now().UTC().Sub(createdAt))
}
开发者ID:kasisnu,项目名称:docker,代码行数:5,代码来源:container.go
注:本文中的github.com/docker/go-units.HumanDuration函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论