kubo/version.go
2025-10-08 18:34:29 +02:00

58 lines
1.3 KiB
Go

package ipfs
import (
"fmt"
"runtime"
"github.com/ipfs/kubo/core/commands/cmdutils"
)
// CurrentCommit is the current git commit, this is set as a ldflag in the Makefile.
var CurrentCommit string
// CurrentVersionNumber is the current application's version literal.
const CurrentVersionNumber = "0.38.1"
const ApiVersion = "/kubo/" + CurrentVersionNumber + "/" //nolint
// RepoVersion is the version number that we are currently expecting to see.
const RepoVersion = 18
// GetUserAgentVersion is the libp2p user agent used by go-ipfs.
//
// Note: This will end in `/` when no commit is available. This is expected.
func GetUserAgentVersion() string {
userAgent := "kubo/" + CurrentVersionNumber + "/" + CurrentCommit
if userAgentSuffix != "" {
if CurrentCommit != "" {
userAgent += "/"
}
userAgent += userAgentSuffix
}
return cmdutils.CleanAndTrim(userAgent)
}
var userAgentSuffix string
func SetUserAgentSuffix(suffix string) {
userAgentSuffix = cmdutils.CleanAndTrim(suffix)
}
type VersionInfo struct {
Version string
Commit string
Repo string
System string
Golang string
}
func GetVersionInfo() *VersionInfo {
return &VersionInfo{
Version: CurrentVersionNumber,
Commit: CurrentCommit,
Repo: fmt.Sprint(RepoVersion),
System: runtime.GOARCH + "/" + runtime.GOOS, // TODO: Precise version here
Golang: runtime.Version(),
}
}