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 ) 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 { 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) }