forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
string.go
45 lines (39 loc) · 1.34 KB
/
string.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package version
import (
"fmt"
"runtime"
"strings"
)
// GitCommit is set in the build script at compile time
var GitCommit string
// Versions contains the versions relevant to a build of avalanchego. In
// addition to supporting construction of the string displayed by
// --version, it is used to produce the output of --version-json and can
// be used to unmarshal that output.
type Versions struct {
Application string `json:"application"`
Database string `json:"database"`
RPCChainVM uint64 `json:"rpcchainvm"`
// Commit may be empty if GitCommit was not set at compile time
Commit string `json:"commit"`
Go string `json:"go"`
}
func GetVersions() *Versions {
return &Versions{
Application: CurrentApp.String(),
Database: CurrentDatabase.String(),
RPCChainVM: uint64(RPCChainVMProtocol),
Commit: GitCommit,
Go: strings.TrimPrefix(runtime.Version(), "go"),
}
}
func (v *Versions) String() string {
// This format maintains consistency with previous --version output
versionString := fmt.Sprintf("%s [database=%s, rpcchainvm=%d, ", v.Application, v.Database, v.RPCChainVM)
if len(v.Commit) > 0 {
versionString += fmt.Sprintf("commit=%s, ", v.Commit)
}
return versionString + fmt.Sprintf("go=%s]", v.Go)
}