lib/api: Returns tags in version as list (#7190)

This commit is contained in:
Jakob Borg 2020-12-10 12:22:09 +01:00 committed by GitHub
parent 7980c8cea2
commit ec5a5d5218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -643,7 +643,7 @@ func (s *service) getSystemVersion(w http.ResponseWriter, r *http.Request) {
"isCandidate": build.IsCandidate, "isCandidate": build.IsCandidate,
"isRelease": build.IsRelease, "isRelease": build.IsRelease,
"date": build.Date, "date": build.Date,
"tags": build.Tags, "tags": build.TagsList(),
"stamp": build.Stamp, "stamp": build.Stamp,
"user": build.User, "user": build.User,
}) })

View File

@ -87,6 +87,13 @@ func LongVersionFor(program string) string {
date := Date.UTC().Format("2006-01-02 15:04:05 MST") date := Date.UTC().Format("2006-01-02 15:04:05 MST")
v := fmt.Sprintf(`%s %s "%s" (%s %s-%s) %s@%s %s`, program, Version, Codename, runtime.Version(), runtime.GOOS, runtime.GOARCH, User, Host, date) v := fmt.Sprintf(`%s %s "%s" (%s %s-%s) %s@%s %s`, program, Version, Codename, runtime.Version(), runtime.GOOS, runtime.GOARCH, User, Host, date)
if tags := TagsList(); len(tags) > 0 {
v = fmt.Sprintf("%s [%s]", v, strings.Join(tags, ", "))
}
return v
}
func TagsList() []string {
tags := strings.Split(Tags, ",") tags := strings.Split(Tags, ",")
if len(tags) == 1 && tags[0] == "" { if len(tags) == 1 && tags[0] == "" {
tags = tags[:0] tags = tags[:0]
@ -96,9 +103,7 @@ func LongVersionFor(program string) string {
tags = append(tags, strings.ToLower(envVar)) tags = append(tags, strings.ToLower(envVar))
} }
} }
if len(tags) > 0 {
sort.Strings(tags) sort.Strings(tags)
v = fmt.Sprintf("%s [%s]", v, strings.Join(tags, ", ")) return tags
}
return v
} }