change version var
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user