Make version print nicely

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2019-10-09 22:18:53 +02:00
parent 8dc088b4dd
commit 2a9ab727c8
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
3 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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
}