gdebug_version.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2019-2020 gf Author(https://github.com/gogf/gf). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package gdebug
  7. import (
  8. "github.com/gogf/gf/crypto/gmd5"
  9. "github.com/gogf/gf/encoding/ghash"
  10. "io/ioutil"
  11. "strconv"
  12. )
  13. // BinVersion returns the version of current running binary.
  14. // It uses ghash.BKDRHash+BASE36 algorithm to calculate the unique version of the binary.
  15. func BinVersion() string {
  16. if binaryVersion == "" {
  17. binaryContent, _ := ioutil.ReadFile(selfPath)
  18. binaryVersion = strconv.FormatInt(
  19. int64(ghash.BKDRHash(binaryContent)),
  20. 36,
  21. )
  22. }
  23. return binaryVersion
  24. }
  25. // BinVersionMd5 returns the version of current running binary.
  26. // It uses MD5 algorithm to calculate the unique version of the binary.
  27. func BinVersionMd5() string {
  28. if binaryVersionMd5 == "" {
  29. binaryVersionMd5, _ = gmd5.EncryptFile(selfPath)
  30. }
  31. return binaryVersionMd5
  32. }