diff --git a/TODO b/TODO index 64173de24..d2e58590a 100644 --- a/TODO +++ b/TODO @@ -9,6 +9,10 @@ orm增加更多数据库支持; ghttp.Response增加输出内容后自动退出当前请求机制,不需要用户手动return,参考beego如何实现; Cookie&Session数据池化处理; ghttp.Client增加proxy特性; +gtime增加对时区转换的封装,并简化失去转换时对类似+80500时区的支持; +改进gf-orm的where查询功能,参考thinkphp 里的where查询语法; + + DONE: 1. gconv完善针对不同类型的判断,例如:尽量减少sprintf("%v", xxx)来执行string类型的转换; diff --git a/g/os/gcmd/gcmd.go b/g/os/gcmd/gcmd.go index d3ff1ce0b..9dac2ba7a 100644 --- a/g/os/gcmd/gcmd.go +++ b/g/os/gcmd/gcmd.go @@ -110,7 +110,7 @@ func (c *gCmdOption) GetBool(key string) bool { return false } -// 绑定命令行参数及对应的命令函数,注意参数是函数的内存地址 +// 绑定命令行参数及对应的命令函数,注意命令函数参数是函数的内存地址 // 如果操作失败返回错误信息 func BindHandle (cmd string, f func()) error { if _, ok := cmdFuncMap[cmd]; ok { diff --git a/g/os/gproc/gproc.go b/g/os/gproc/gproc.go index cd223c12a..ac17cf2b0 100644 --- a/g/os/gproc/gproc.go +++ b/g/os/gproc/gproc.go @@ -17,8 +17,9 @@ import ( ) const ( - gPROC_ENV_KEY_PPID_KEY = "gproc.ppid" - gPROC_TEMP_DIR_ENV_KEY = "gproc.tempdir" + gPROC_ENV_KEY_PPID_KEY = "GPROC_PPID" + gPROC_ENV_KEY_COMM_KEY = "GPROC_COMM_ENABLED" + gPROC_TEMP_DIR_ENV_KEY = "GPROC_TEMP_DIR" ) // 进程开始执行时间 @@ -36,7 +37,7 @@ func PPid() int { } // gPROC_ENV_KEY_PPID_KEY为gproc包自定义的父进程 ppidValue := os.Getenv(gPROC_ENV_KEY_PPID_KEY) - if ppidValue != "" { + if ppidValue != "" && ppidValue != "0" { return gconv.Int(ppidValue) } return PPidOS() @@ -49,7 +50,8 @@ func PPidOS() int { // 判断当前进程是否为gproc创建的子进程 func IsChild() bool { - return os.Getenv(gPROC_ENV_KEY_PPID_KEY) != "" + ppidValue := os.Getenv(gPROC_ENV_KEY_PPID_KEY) + return ppidValue != "" && ppidValue != "0" } // 设置gproc父进程ID,当ppid为0时表示该进程为gproc主进程,否则为gproc子进程 diff --git a/g/os/gproc/gproc_comm.go b/g/os/gproc/gproc_comm.go index 4bb548de6..c80135feb 100644 --- a/g/os/gproc/gproc_comm.go +++ b/g/os/gproc/gproc_comm.go @@ -37,7 +37,9 @@ type sendQueueItem struct { // 进程管理/通信初始化操作 func init() { - go startTcpListening() + if os.Getenv(gPROC_ENV_KEY_COMM_KEY) == "1" { + go startTcpListening() + } } // 获取指定进程的通信文件地址 diff --git a/g/os/gproc/gproc_manager.go b/g/os/gproc/gproc_manager.go index 977c855c7..ed12d4ac7 100644 --- a/g/os/gproc/gproc_manager.go +++ b/g/os/gproc/gproc_manager.go @@ -9,10 +9,7 @@ package gproc import ( "os" - "strings" - "os/exec" "gitee.com/johng/gf/g/container/gmap" - "fmt" ) // 进程管理器 @@ -27,40 +24,6 @@ func NewManager() *Manager { } } -// 创建一个进程(不执行) -func NewProcess(path string, args []string, environment []string) *Process { - env := make([]string, len(environment) + 1) - for k, v := range environment { - env[k] = v - } - env[len(env) - 1] = fmt.Sprintf("%s=%s", gPROC_TEMP_DIR_ENV_KEY, os.TempDir()) - p := &Process { - Manager : nil, - PPid : os.Getpid(), - Cmd : exec.Cmd { - Args : []string{path}, - Path : path, - Stdin : os.Stdin, - Stdout : os.Stdout, - Stderr : os.Stderr, - Env : env, - ExtraFiles : make([]*os.File, 0), - }, - } - // 当前工作目录 - if d, err := os.Getwd(); err == nil { - p.Dir = d - } - if len(args) > 0 { - start := 0 - if strings.EqualFold(path, args[0]) { - start = 1 - } - p.Args = append(p.Args, args[start : ]...) - } - return p -} - // 创建一个进程(不执行) func (m *Manager) NewProcess(path string, args []string, environment []string) *Process { p := NewProcess(path, args, environment) diff --git a/g/os/gproc/gproc_proccess.go b/g/os/gproc/gproc_proccess.go index 4db879f50..7ffab8295 100644 --- a/g/os/gproc/gproc_proccess.go +++ b/g/os/gproc/gproc_proccess.go @@ -11,13 +11,50 @@ import ( "fmt" "os/exec" "errors" + "strings" ) // 子进程 type Process struct { exec.Cmd - Manager *Manager // 所属进程管理器 - PPid int // 自定义关联的父进程ID + Manager *Manager // 所属进程管理器 + PPid int // 自定义关联的父进程ID + CommEnabled bool // 是否开启TCP通信监听服务 +} + +// 创建一个进程(不执行) +func NewProcess(path string, args []string, environment []string) *Process { + env := make([]string, len(environment) + 1) + for k, v := range environment { + env[k] = v + } + env[len(env) - 1] = fmt.Sprintf("%s=%s", gPROC_TEMP_DIR_ENV_KEY, os.TempDir()) + p := &Process { + Manager : nil, + PPid : os.Getpid(), + CommEnabled : true, + Cmd : exec.Cmd { + Args : []string{path}, + Path : path, + Stdin : os.Stdin, + Stdout : os.Stdout, + Stderr : os.Stderr, + Env : env, + ExtraFiles : make([]*os.File, 0), + }, + } + // 当前工作目录 + if d, err := os.Getwd(); err == nil { + p.Dir = d + } + if len(args) > 0 { + start := 0 + if strings.EqualFold(path, args[0]) { + start = 1 + } + p.Args = append(p.Args, args[start : ]...) + } + return p } // 开始执行(非阻塞) @@ -25,9 +62,12 @@ func (p *Process) Start() (int, error) { if p.Process != nil { return p.Pid(), nil } - if p.PPid > 0 { - p.Env = append(p.Env, fmt.Sprintf("%s=%d", gPROC_ENV_KEY_PPID_KEY, p.PPid)) + commEnabled := 0 + if p.CommEnabled { + commEnabled = 1 } + p.Env = append(p.Env, fmt.Sprintf("%s=%d", gPROC_ENV_KEY_PPID_KEY, p.PPid)) + p.Env = append(p.Env, fmt.Sprintf("%s=%d", gPROC_ENV_KEY_COMM_KEY, commEnabled)) if err := p.Cmd.Start(); err == nil { if p.Manager != nil { p.Manager.processes.Set(p.Process.Pid, p) diff --git a/g/os/gtime/gtime.go b/g/os/gtime/gtime.go index 889e62e3b..5a1214511 100644 --- a/g/os/gtime/gtime.go +++ b/g/os/gtime/gtime.go @@ -15,6 +15,10 @@ import ( "errors" ) +const ( + TIME_REAGEX_PATTERN = `(\d{4}-\d{2}-\d{2})[\sT]{0,1}(\d{2}:\d{2}:\d{2}){0,1}\.{0,1}(\d{0,9})([\sZ]{0,1})([\+-]{0,1})([:\d]*)` +) + var ( // 用于time.Time转换使用,防止多次Compile timeRegex *regexp.Regexp @@ -22,7 +26,7 @@ var ( func init() { // 使用正则判断会比直接使用ParseInLocation挨个轮训判断要快很多 - timeRegex, _ = regexp.Compile(`(\d{4}-\d{2}-\d{2})[\sT]{0,1}(\d{2}:\d{2}:\d{2}){0,1}\.{0,1}(\d{0,9})([\sZ]{0,1})([\+-]{0,1})([:\d]*)`) + timeRegex, _ = regexp.Compile(TIME_REAGEX_PATTERN) } diff --git a/geg/other/test.go b/geg/other/test.go index 7b38824b0..5d0e543e1 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -8,5 +8,4 @@ import ( func main() { fmt.Println(gconv.Float64(float32(19.66))) fmt.Println(float64(float32(19.66))) - -} \ No newline at end of file +}