github.com/gogf/gf@v1.16.9/debug/gdebug/gdebug_version.go (about) 1 // Copyright GoFrame Author(https://goframe.org). 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 7 package gdebug 8 9 import ( 10 "github.com/gogf/gf/crypto/gmd5" 11 "github.com/gogf/gf/encoding/ghash" 12 "io/ioutil" 13 "strconv" 14 ) 15 16 // BinVersion returns the version of current running binary. 17 // It uses ghash.BKDRHash+BASE36 algorithm to calculate the unique version of the binary. 18 func BinVersion() string { 19 if binaryVersion == "" { 20 binaryContent, _ := ioutil.ReadFile(selfPath) 21 binaryVersion = strconv.FormatInt( 22 int64(ghash.BKDRHash(binaryContent)), 23 36, 24 ) 25 } 26 return binaryVersion 27 } 28 29 // BinVersionMd5 returns the version of current running binary. 30 // It uses MD5 algorithm to calculate the unique version of the binary. 31 func BinVersionMd5() string { 32 if binaryVersionMd5 == "" { 33 binaryVersionMd5, _ = gmd5.EncryptFile(selfPath) 34 } 35 return binaryVersionMd5 36 }