當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Time.IsZero方法代碼示例

本文整理匯總了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/util.Time.IsZero方法的典型用法代碼示例。如果您正苦於以下問題:Golang Time.IsZero方法的具體用法?Golang Time.IsZero怎麽用?Golang Time.IsZero使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/GoogleCloudPlatform/kubernetes/pkg/util.Time的用法示例。


在下文中一共展示了Time.IsZero方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: describeBuildStatus

func describeBuildStatus(build *buildapi.Build, t *util.Time, parentName string) string {
	if t == nil {
		ts := buildTimestamp(build)
		t = &ts
	}
	var time string
	if t.IsZero() {
		time = "<unknown>"
	} else {
		time = strings.ToLower(formatRelativeTime(t.Time))
	}
	name := build.Name
	prefix := parentName + "-"
	if strings.HasPrefix(name, prefix) {
		name = name[len(prefix):]
	}
	revision := describeSourceRevision(build.Parameters.Revision)
	if len(revision) != 0 {
		revision = fmt.Sprintf(" - %s", revision)
	}
	switch build.Status {
	case buildapi.BuildStatusComplete:
		return fmt.Sprintf("build %s succeeded %s ago%s", name, time, revision)
	case buildapi.BuildStatusError:
		return fmt.Sprintf("build %s stopped with an error %s ago%s", name, time, revision)
	case buildapi.BuildStatusFailed:
		return fmt.Sprintf("build %s failed %s ago%s", name, time, revision)
	default:
		status := strings.ToLower(string(build.Status))
		return fmt.Sprintf("build %s %s for %s%s", name, status, time, revision)
	}
}
開發者ID:cjnygard,項目名稱:origin,代碼行數:32,代碼來源:projectstatus.go

示例2: printImageStream

func printImageStream(stream *imageapi.ImageStream, w io.Writer, withNamespace, wide bool, columnLabels []string) error {
	tags := ""
	set := util.NewStringSet()
	var latest util.Time
	for tag, list := range stream.Status.Tags {
		set.Insert(tag)
		if len(list.Items) > 0 {
			if list.Items[0].Created.After(latest.Time) {
				latest = list.Items[0].Created
			}
		}
	}
	latestTime := ""
	if !latest.IsZero() {
		latestTime = fmt.Sprintf("%s ago", formatRelativeTime(latest.Time))
	}
	tags = strings.Join(set.List(), ",")
	_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", stream.Name, stream.Status.DockerImageRepository, tags, latestTime)
	return err
}
開發者ID:patrykattc,項目名稱:origin,代碼行數:20,代碼來源:printer.go

示例3: describeBuildPhase

func describeBuildPhase(build *buildapi.Build, t *util.Time, parentName string, pushTargetResolved bool) string {
	imageStreamFailure := ""
	// if we're using an image stream and that image stream is the internal registry and that registry doesn't exist
	if (build.Spec.Output.To != nil) && !pushTargetResolved {
		imageStreamFailure = " (can't push to image)"
	}

	if t == nil {
		ts := buildTimestamp(build)
		t = &ts
	}
	var time string
	if t.IsZero() {
		time = "<unknown>"
	} else {
		time = strings.ToLower(formatRelativeTime(t.Time))
	}
	name := build.Name
	prefix := parentName + "-"
	if strings.HasPrefix(name, prefix) {
		name = name[len(prefix):]
	}
	revision := describeSourceRevision(build.Spec.Revision)
	if len(revision) != 0 {
		revision = fmt.Sprintf(" - %s", revision)
	}
	switch build.Status.Phase {
	case buildapi.BuildPhaseComplete:
		return fmt.Sprintf("build %s succeeded %s ago%s%s", name, time, revision, imageStreamFailure)
	case buildapi.BuildPhaseError:
		return fmt.Sprintf("build %s stopped with an error %s ago%s%s", name, time, revision, imageStreamFailure)
	case buildapi.BuildPhaseFailed:
		return fmt.Sprintf("build %s failed %s ago%s%s", name, time, revision, imageStreamFailure)
	default:
		status := strings.ToLower(string(build.Status.Phase))
		return fmt.Sprintf("build %s %s for %s%s%s", name, status, time, revision, imageStreamFailure)
	}
}
開發者ID:heriipurnama,項目名稱:origin,代碼行數:38,代碼來源:projectstatus.go


注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/util.Time.IsZero方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。