2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2020-03-16 22:47:39 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
|
|
|
package gdebug
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"strconv"
|
2021-11-13 23:23:55 +08:00
|
|
|
|
|
|
|
"github.com/gogf/gf/v2/crypto/gmd5"
|
|
|
|
"github.com/gogf/gf/v2/encoding/ghash"
|
2020-03-16 22:47:39 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// BinVersion returns the version of current running binary.
|
|
|
|
// It uses ghash.BKDRHash+BASE36 algorithm to calculate the unique version of the binary.
|
|
|
|
func BinVersion() string {
|
|
|
|
if binaryVersion == "" {
|
|
|
|
binaryContent, _ := ioutil.ReadFile(selfPath)
|
|
|
|
binaryVersion = strconv.FormatInt(
|
|
|
|
int64(ghash.BKDRHash(binaryContent)),
|
|
|
|
36,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return binaryVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
// BinVersionMd5 returns the version of current running binary.
|
|
|
|
// It uses MD5 algorithm to calculate the unique version of the binary.
|
|
|
|
func BinVersionMd5() string {
|
|
|
|
if binaryVersionMd5 == "" {
|
|
|
|
binaryVersionMd5, _ = gmd5.EncryptFile(selfPath)
|
|
|
|
}
|
|
|
|
return binaryVersionMd5
|
|
|
|
}
|