change version var

This commit is contained in:
2026-02-08 22:52:26 +01:00
parent d1e54774a7
commit 557a73a8b4
3 changed files with 6 additions and 60 deletions

View File

@@ -1,65 +1,9 @@
package constant
import (
"fmt"
"strconv"
)
type (
Version struct {
patch int
minor int
major int
}
)
var (
patch string = "0"
minor string = "0"
major string = "0"
version Version
version string
)
func init() {
patchInt, err := strconv.Atoi(patch)
if err != nil {
panic(fmt.Errorf("failed to parse version number, this is a compilation error, try recompile the program"))
}
minorInt, err := strconv.Atoi(minor)
if err != nil {
panic(fmt.Errorf("failed to parse version number, this is a compilation error, try recompile the program"))
}
majorInt, err := strconv.Atoi(major)
if err != nil {
panic(fmt.Errorf("failed to parse version number, this is a compilation error, try recompile the program"))
}
version = Version{
patch: patchInt,
minor: minorInt,
major: majorInt,
}
}
func ProgramVersion() Version {
func ProgramVersion() string {
return version
}
func (v Version) Patch() int {
return v.patch
}
func (v Version) Minor() int {
return v.minor
}
func (v Version) Major() int {
return v.major
}
func (v Version) String() string {
return fmt.Sprintf("%d.%d.%d", v.major, v.minor, v.patch)
}