change errors wrapped by gerror.Wrap with error stack info for all packages

This commit is contained in:
John Guo
2021-12-21 22:59:14 +08:00
parent 7e81600772
commit ce93b625d4
67 changed files with 590 additions and 322 deletions

View File

@ -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
}