mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
gfile包增加GoRootOfBuild方法,用于获取编译时的GOROOT数值;并改进glog包中backtrace的GOROOT路径过滤处理;TODO++
This commit is contained in:
2
TODO
2
TODO
@ -8,6 +8,8 @@ orm增加更多数据库支持;
|
||||
增加可选择性的orm tag特性,用以数据表记录与struct对象转换的键名属性映射;
|
||||
ghttp.Response增加输出内容后自动退出当前请求机制,不需要用户手动return,参考beego如何实现;
|
||||
对grpool进行优化改进,包括属性原子操作封装采用gtype实现,修正设计BUG:https://github.com/johng-cn/gf/issues/6;
|
||||
平滑重启机制改进,去掉多进程模式,改为单进程模式,以便于开发阶段调试;
|
||||
|
||||
|
||||
DONE:
|
||||
1. gconv完善针对不同类型的判断,例如:尽量减少sprintf("%v", xxx)来执行string类型的转换;
|
||||
|
||||
@ -33,7 +33,10 @@ const (
|
||||
)
|
||||
|
||||
// 源码的main包所在目录,仅仅会设置一次
|
||||
var mainPkgPath = gtype.NewInterface()
|
||||
var mainPkgPath = gtype.NewString()
|
||||
|
||||
// 编译时的 GOROOT 数值
|
||||
var goRootOfBuild = gtype.NewString()
|
||||
|
||||
// 给定文件的绝对路径创建文件
|
||||
func Mkdir(path string) error {
|
||||
@ -457,17 +460,18 @@ func GetBinContentByTwoOffsets(file *os.File, start int64, end int64) []byte {
|
||||
return buffer
|
||||
}
|
||||
|
||||
// 获取入口函数文件所在目录(main包文件目录),仅对源码开发环境有效(即仅对生成该可执行文件的系统下有效)
|
||||
// 获取入口函数文件所在目录(main包文件目录),
|
||||
// **仅对源码开发环境有效(即仅对生成该可执行文件的系统下有效)**
|
||||
func MainPkgPath() string {
|
||||
path := mainPkgPath.Val()
|
||||
if path != nil {
|
||||
return path.(string)
|
||||
if path != "" {
|
||||
return path
|
||||
}
|
||||
f := ""
|
||||
for i := 1; i < 10000; i++ {
|
||||
if _, file, _, ok := runtime.Caller(i); ok {
|
||||
// 不包含go源码路径
|
||||
if !gregx.IsMatchString("^" + runtime.GOROOT(), file) {
|
||||
if !gregx.IsMatchString("^" + GoRootOfBuild(), file) {
|
||||
f = file
|
||||
}
|
||||
} else {
|
||||
@ -482,6 +486,33 @@ func MainPkgPath() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 编译时环境的GOROOT数值
|
||||
func GoRootOfBuild() string {
|
||||
if v := goRootOfBuild.Val(); v != "" {
|
||||
return v
|
||||
}
|
||||
firstEntry := ""
|
||||
for i := 0; i < 10000; i++ {
|
||||
if _, file, _, ok := runtime.Caller(i); ok {
|
||||
firstEntry = file
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(firstEntry) > 0 {
|
||||
sep := "/"
|
||||
array := strings.Split(firstEntry, sep)
|
||||
if len(array) == 1 {
|
||||
sep = "\\"
|
||||
array = strings.Split(firstEntry, sep)
|
||||
}
|
||||
root := strings.Join(array[0 : len(array) - 3], sep)
|
||||
goRootOfBuild.Set(root)
|
||||
return root
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// 系统临时目录
|
||||
func TempDir() string {
|
||||
return os.TempDir()
|
||||
|
||||
@ -146,7 +146,7 @@ func (l *Logger) backtrace() string {
|
||||
for i := 1; i < 10000; i++ {
|
||||
if _, cfile, cline, ok := runtime.Caller(i + l.btSkip.Val()); ok {
|
||||
// 不打印出go源码路径
|
||||
if !gregx.IsMatchString("^" + runtime.GOROOT(), cfile) {
|
||||
if !gregx.IsMatchString("^" + gfile.GoRootOfBuild(), cfile) {
|
||||
backtrace += strconv.Itoa(index) + ". " + cfile + ":" + strconv.Itoa(cline) + ln
|
||||
index++
|
||||
}
|
||||
|
||||
@ -1,22 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"gitee.com/johng/gf/g"
|
||||
"gitee.com/johng/gf/g/os/gproc"
|
||||
)
|
||||
import "gitee.com/johng/gf/g/os/glog"
|
||||
|
||||
func main() {
|
||||
if !gproc.IsChild() {
|
||||
go func() {
|
||||
for {
|
||||
fmt.Println("test")
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
}()
|
||||
}
|
||||
s := g.Server()
|
||||
s.SetPort(9000)
|
||||
s.Run()
|
||||
glog.Error(1)
|
||||
}
|
||||
Reference in New Issue
Block a user