/ version.go
version.go
1 package ipfs 2 3 import ( 4 "fmt" 5 "runtime" 6 7 "github.com/ipfs/kubo/core/commands/cmdutils" 8 ) 9 10 // CurrentCommit is the current git commit, this is set as a ldflag in the Makefile. 11 var CurrentCommit string 12 13 // taggedRelease is set via ldflag when building from a version-tagged commit 14 // with a clean tree. When set, the commit hash is omitted from the libp2p 15 // identify agent version and the HTTP user agent, since the version number 16 // already identifies the exact source. 17 var taggedRelease string 18 19 // CurrentVersionNumber is the current application's version literal. 20 const CurrentVersionNumber = "0.41.0-dev" 21 22 const ApiVersion = "/kubo/" + CurrentVersionNumber + "/" //nolint 23 24 // RepoVersion is the version number that we are currently expecting to see. 25 const RepoVersion = 18 26 27 // GetUserAgentVersion is the libp2p user agent used by go-ipfs. 28 func GetUserAgentVersion() string { 29 // For tagged release builds with a clean tree, the commit hash is 30 // redundant since the version number identifies the exact source. 31 commit := CurrentCommit 32 if taggedRelease != "" { 33 commit = "" 34 } 35 36 userAgent := "kubo/" + CurrentVersionNumber 37 if commit != "" { 38 userAgent += "/" + commit 39 } 40 if userAgentSuffix != "" { 41 userAgent += "/" + userAgentSuffix 42 } 43 return cmdutils.CleanAndTrim(userAgent) 44 } 45 46 var userAgentSuffix string 47 48 func SetUserAgentSuffix(suffix string) { 49 userAgentSuffix = cmdutils.CleanAndTrim(suffix) 50 } 51 52 type VersionInfo struct { 53 Version string 54 Commit string 55 Repo string 56 System string 57 Golang string 58 } 59 60 func GetVersionInfo() *VersionInfo { 61 return &VersionInfo{ 62 Version: CurrentVersionNumber, 63 Commit: CurrentCommit, 64 Repo: fmt.Sprint(RepoVersion), 65 System: runtime.GOARCH + "/" + runtime.GOOS, // TODO: Precise version here 66 Golang: runtime.Version(), 67 } 68 }