improve gfile/gstr/ghttp

This commit is contained in:
John
2019-09-23 16:21:19 +08:00
parent 02e467fb57
commit 3218c89f17
17 changed files with 330 additions and 68 deletions

View File

@ -12,7 +12,13 @@ import (
"fmt"
"path/filepath"
"runtime"
"strconv"
"strings"
"github.com/gogf/gf/encoding/ghash"
"github.com/gogf/gf/crypto/gmd5"
"github.com/gogf/gf/os/gfile"
)
const (
@ -21,8 +27,9 @@ const (
)
var (
// goRootForFilter is used for stack filtering purpose.
goRootForFilter = runtime.GOROOT()
goRootForFilter = runtime.GOROOT() // goRootForFilter is used for stack filtering purpose.
binaryVersion = "" // The version of current running binary(uint64 hex).
binaryVersionMd5 = "" // The version of current running binary(MD5).
)
func init() {
@ -31,6 +38,27 @@ func init() {
}
}
// 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 == "" {
binaryVersion = strconv.FormatInt(
int64(ghash.BKDRHash(gfile.GetBytes(gfile.SelfPath()))),
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(gfile.SelfPath())
}
return binaryVersionMd5
}
// PrintStack prints to standard error the stack trace returned by runtime.Stack.
func PrintStack(skip ...int) {
fmt.Print(Stack(skip...))