From ec5a5d5218500ad0ceee927a8a64afe407c8522c Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Thu, 10 Dec 2020 12:22:09 +0100 Subject: [PATCH] lib/api: Returns tags in version as list (#7190) --- lib/api/api.go | 2 +- lib/build/build.go | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/api/api.go b/lib/api/api.go index fd660e642..94ce45840 100644 --- a/lib/api/api.go +++ b/lib/api/api.go @@ -643,7 +643,7 @@ func (s *service) getSystemVersion(w http.ResponseWriter, r *http.Request) { "isCandidate": build.IsCandidate, "isRelease": build.IsRelease, "date": build.Date, - "tags": build.Tags, + "tags": build.TagsList(), "stamp": build.Stamp, "user": build.User, }) diff --git a/lib/build/build.go b/lib/build/build.go index 69a509b21..285cf65e7 100644 --- a/lib/build/build.go +++ b/lib/build/build.go @@ -87,6 +87,13 @@ func LongVersionFor(program string) string { 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) + if tags := TagsList(); len(tags) > 0 { + v = fmt.Sprintf("%s [%s]", v, strings.Join(tags, ", ")) + } + return v +} + +func TagsList() []string { tags := strings.Split(Tags, ",") if len(tags) == 1 && tags[0] == "" { tags = tags[:0] @@ -96,9 +103,7 @@ func LongVersionFor(program string) string { tags = append(tags, strings.ToLower(envVar)) } } - if len(tags) > 0 { - sort.Strings(tags) - v = fmt.Sprintf("%s [%s]", v, strings.Join(tags, ", ")) - } - return v + + sort.Strings(tags) + return tags }