From c961aea144468aeb5798c6e949db6d01a1531d74 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 12 Apr 2022 11:43:34 +0300 Subject: [PATCH] [#170] version: Add specification string encoder Signed-off-by: Alex Vanin --- version/version.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/version/version.go b/version/version.go index 76cad82e..881b0a5e 100644 --- a/version/version.go +++ b/version/version.go @@ -62,9 +62,17 @@ func (v *Version) ReadFromV2(m refs.Version) { *v = Version(m) } -// String returns semver formatted value without patch and with v prefix, -// e.g. 'v2.1'. +// String implements fmt.Stringer. +// +// String is designed to be human-readable, and its format MAY differ between +// SDK versions. func (v Version) String() string { + return EncodeToString(v) +} + +// EncodeToString encodes version according to format from specification: +// semver formatted value without patch and with v prefix, e.g. 'v2.1'. +func EncodeToString(v Version) string { return fmt.Sprintf("v%d.%d", v.Major(), v.Minor()) }