mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-28 00:03:39 +00:00
Just some name changes, put in a stand in emission amount, and started copying the algo from Karlsen. Not release worthy yet. Therefore Dev branch exists now. Also, for now this is for research purposes only. I got no clue what to build on top of Kaspa yet. Help would be appreciated for ideas and implementations.
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package version
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// validCharacters is a list of characters valid in the appBuild string
|
|
const validCharacters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
|
|
|
|
const (
|
|
appMajor uint = 0
|
|
appMinor uint = 12
|
|
appPatch uint = 14
|
|
)
|
|
|
|
// appBuild is defined as a variable so it can be overridden during the build
|
|
// process with '-ldflags "-X github.com/zoomy-network/zoomyd/version.appBuild=foo"' if needed.
|
|
// It MUST only contain characters from validCharacters.
|
|
var appBuild string
|
|
|
|
var version = "" // string used for memoization of version
|
|
|
|
func init() {
|
|
if version == "" {
|
|
// Start with the major, minor, and patch versions.
|
|
version = fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch)
|
|
|
|
// Append build metadata if there is any.
|
|
// Panic if any invalid characters are encountered
|
|
if appBuild != "" {
|
|
checkAppBuild(appBuild)
|
|
|
|
version = fmt.Sprintf("%s-%s", version, appBuild)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Version returns the application version as a properly formed string
|
|
func Version() string {
|
|
return version
|
|
}
|
|
|
|
// checkAppBuild verifies that appBuild does not contain any characters outside of validCharacters.
|
|
// In case of any invalid characters checkAppBuild panics
|
|
func checkAppBuild(appBuild string) {
|
|
for _, r := range appBuild {
|
|
if !strings.ContainsRune(validCharacters, r) {
|
|
panic(fmt.Errorf("appBuild string (%s) contains forbidden characters. Only alphanumeric characters and dashes are allowed", appBuild))
|
|
}
|
|
}
|
|
}
|