mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
change errors wrapped by gerror.Wrap with error stack info for all packages
This commit is contained in:
@ -7,11 +7,15 @@
|
||||
package gdebug
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/gogf/gf/v2/crypto/gmd5"
|
||||
"github.com/gogf/gf/v2/encoding/ghash"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
// BinVersion returns the version of current running binary.
|
||||
@ -31,7 +35,24 @@ func BinVersion() string {
|
||||
// It uses MD5 algorithm to calculate the unique version of the binary.
|
||||
func BinVersionMd5() string {
|
||||
if binaryVersionMd5 == "" {
|
||||
binaryVersionMd5, _ = gmd5.EncryptFile(selfPath)
|
||||
binaryVersionMd5, _ = md5File(selfPath)
|
||||
}
|
||||
return binaryVersionMd5
|
||||
}
|
||||
|
||||
// md5File encrypts file content of `path` using MD5 algorithms.
|
||||
func md5File(path string) (encrypt string, err error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
err = gerror.Wrapf(err, `os.Open failed for name "%s"`, path)
|
||||
return "", err
|
||||
}
|
||||
defer f.Close()
|
||||
h := md5.New()
|
||||
_, err = io.Copy(h, f)
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, `io.Copy failed`)
|
||||
return "", err
|
||||
}
|
||||
return fmt.Sprintf("%x", h.Sum(nil)), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user