From 2a9ab727c8203faae1a58ba39b9d1e6bf01bd336 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 9 Oct 2019 22:18:53 +0200 Subject: [PATCH] Make version print nicely License: MIT Signed-off-by: Jakub Sztandera --- api/api.go | 7 +++++++ build/version.go | 5 +++++ node/impl/common.go | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/api/api.go b/api/api.go index 13e564818..ccdcb0313 100644 --- a/api/api.go +++ b/api/api.go @@ -2,6 +2,7 @@ package api import ( "context" + "fmt" "github.com/ipfs/go-cid" "github.com/ipfs/go-filestore" @@ -9,6 +10,7 @@ import ( "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" + "github.com/filecoin-project/go-lotus/build" "github.com/filecoin-project/go-lotus/chain/address" "github.com/filecoin-project/go-lotus/chain/store" "github.com/filecoin-project/go-lotus/chain/types" @@ -173,6 +175,11 @@ type Version struct { // TODO: git commit / os / genesis cid? } +func (v Version) String() string { + vM, vm, vp := build.VersionInts(v.APIVersion) + return fmt.Sprintf("%s+api%d.%d.%d", v.Version, vM, vm, vp) +} + type Import struct { Status filestore.Status Key cid.Cid diff --git a/build/version.go b/build/version.go index 339a6bf8a..33109762d 100644 --- a/build/version.go +++ b/build/version.go @@ -19,3 +19,8 @@ const ( MinorMask = 0xffff00 PatchMask = 0xffffff ) + +// VersionInts returns (major, minor, patch) versions +func VersionInts(version uint32) (uint32, uint32, uint32) { + return (version & MajorMask) >> 16, (version & MinorMask) >> 8, version & PatchMask +} diff --git a/node/impl/common.go b/node/impl/common.go index 571760c5e..0e2080212 100644 --- a/node/impl/common.go +++ b/node/impl/common.go @@ -85,7 +85,8 @@ func (a *CommonAPI) ID(context.Context) (peer.ID, error) { func (a *CommonAPI) Version(context.Context) (api.Version, error) { return api.Version{ - Version: build.Version, + Version: build.Version, + APIVersion: build.APIVersion, }, nil }