mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 20:28:17 +08:00
merge develop
This commit is contained in:
commit
add7dd5a45
10
.example/debug/gdebug/gdebug_info.go
Normal file
10
.example/debug/gdebug/gdebug_info.go
Normal file
@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(gdebug.BuildInfo())
|
||||
}
|
@ -2,16 +2,16 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/os/gproc"
|
||||
)
|
||||
|
||||
// 使用gproc kill指定其他进程(清确保运行该程序的用户有足够权限)
|
||||
func main() {
|
||||
pid := 28536
|
||||
pid := 14746
|
||||
m := gproc.NewManager()
|
||||
m.AddProcess(pid)
|
||||
m.KillAll()
|
||||
err := m.KillAll()
|
||||
fmt.Println(err)
|
||||
m.WaitAll()
|
||||
fmt.Printf("%d was killed\n", pid)
|
||||
}
|
||||
|
@ -14,4 +14,5 @@ func main() {
|
||||
})
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/text/gregex"
|
||||
"github.com/gogf/gf/os/gproc"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := `-abc`
|
||||
m, err := gregex.MatchString(`^\-{1,2}a={0,1}(.*)`, s)
|
||||
g.Dump(err)
|
||||
g.Dump(m)
|
||||
process := gproc.NewProcessCmd("go run test.go")
|
||||
if pid, err := process.Start(); err != nil {
|
||||
log.Print("Build failed:", err)
|
||||
return
|
||||
} else {
|
||||
log.Printf("Build running: pid: %d", pid)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ package gdebug
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/gogf/gf"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
@ -28,6 +29,9 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
buildTime = "" // Binary time string, which is injected from "go build -ldflags '-X importpath.name=value'".
|
||||
buildGoVersion = "" // Binary go version, which is injected from "go build -ldflags '-X importpath.name=value'".
|
||||
buildGitCommit = "" // Binary git commit, which is injected from "go build -ldflags '-X importpath.name=value'".
|
||||
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).
|
||||
@ -39,6 +43,18 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
// BuildInfo returns the built information of the binary.
|
||||
// Note that it should be used with gf-cli tool: gf build,
|
||||
// which injects necessary information into the binary.
|
||||
func BuildInfo() map[string]string {
|
||||
return map[string]string{
|
||||
"gf": gf.VERSION,
|
||||
"go": buildGoVersion,
|
||||
"git": buildGitCommit,
|
||||
"time": buildTime,
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
|
@ -63,14 +63,16 @@ type (
|
||||
|
||||
// Router item just for dumping.
|
||||
RouterItem struct {
|
||||
Type int
|
||||
Middleware string
|
||||
Domain string
|
||||
Method string
|
||||
Route string
|
||||
Priority int
|
||||
IsServiceHandler bool
|
||||
handler *handlerItem
|
||||
Server string
|
||||
Address string
|
||||
Domain string
|
||||
Type int
|
||||
Middleware string
|
||||
Method string
|
||||
Route string
|
||||
Priority int
|
||||
IsServiceHandler bool
|
||||
handler *handlerItem
|
||||
}
|
||||
|
||||
// 路由函数注册信息
|
||||
@ -319,7 +321,7 @@ func (s *Server) Start() error {
|
||||
if gproc.IsChild() {
|
||||
gtimer.SetTimeout(2*time.Second, func() {
|
||||
if err := gproc.Send(gproc.PPid(), []byte("exit"), gADMIN_GPROC_COMM_GROUP); err != nil {
|
||||
glog.Error("[ghttp] server error in process communication:", err)
|
||||
//glog.Error("[ghttp] server error in process communication:", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -348,18 +350,11 @@ func (s *Server) DumpRouterMap() {
|
||||
tablewriter.ALIGN_LEFT,
|
||||
})
|
||||
|
||||
address := s.config.Address
|
||||
if s.config.HTTPSAddr != "" {
|
||||
if len(address) > 0 {
|
||||
address += ","
|
||||
}
|
||||
address += "tls" + s.config.HTTPSAddr
|
||||
}
|
||||
for _, array := range s.GetRouterMap() {
|
||||
data := make([]string, 8)
|
||||
for _, item := range array {
|
||||
data[0] = s.name
|
||||
data[1] = address
|
||||
data[0] = item.Server
|
||||
data[1] = item.Address
|
||||
data[2] = item.Domain
|
||||
data[3] = item.Method
|
||||
data[4] = gconv.String(len(strings.Split(item.Route, "/")) - 1 + item.Priority)
|
||||
@ -378,13 +373,22 @@ func (s *Server) DumpRouterMap() {
|
||||
// The key of the returned map is the domain of the server.
|
||||
func (s *Server) GetRouterMap() map[string][]RouterItem {
|
||||
m := make(map[string]*garray.SortedArray)
|
||||
address := s.config.Address
|
||||
if s.config.HTTPSAddr != "" {
|
||||
if len(address) > 0 {
|
||||
address += ","
|
||||
}
|
||||
address += "tls" + s.config.HTTPSAddr
|
||||
}
|
||||
for k, registeredItems := range s.routesMap {
|
||||
array, _ := gregex.MatchString(`(.*?)%([A-Z]+):(.+)@(.+)`, k)
|
||||
for index, registeredItem := range registeredItems {
|
||||
item := RouterItem{
|
||||
Server: s.name,
|
||||
Address: address,
|
||||
Domain: array[4],
|
||||
Type: registeredItem.handler.itemType,
|
||||
Middleware: array[1],
|
||||
Domain: array[4],
|
||||
Method: array[2],
|
||||
Route: array[3],
|
||||
Priority: len(registeredItems) - index - 1,
|
||||
|
@ -60,6 +60,11 @@ func NewProcess(path string, args []string, environment ...[]string) *Process {
|
||||
return p
|
||||
}
|
||||
|
||||
// NewProcessCmd creates and returns a process with given command and optional environment variable array.
|
||||
func NewProcessCmd(cmd string, environment ...[]string) *Process {
|
||||
return NewProcess(getShell(), []string{getShellOption(), cmd}, environment...)
|
||||
}
|
||||
|
||||
// 开始执行(非阻塞)
|
||||
func (p *Process) Start() (int, error) {
|
||||
if p.Process != nil {
|
||||
@ -114,6 +119,8 @@ func (p *Process) Kill() error {
|
||||
if p.Manager != nil {
|
||||
p.Manager.processes.Remove(p.Pid())
|
||||
}
|
||||
p.Process.Release()
|
||||
p.Process.Wait()
|
||||
return nil
|
||||
} else {
|
||||
return err
|
@ -53,7 +53,7 @@ func Struct(params interface{}, pointer interface{}, mapping ...map[string]strin
|
||||
if !ok {
|
||||
rv := reflect.ValueOf(pointer)
|
||||
if kind := rv.Kind(); kind != reflect.Ptr {
|
||||
return fmt.Errorf("object pointer should be type of: %v", kind)
|
||||
return fmt.Errorf("object pointer should be type of '*struct', but got '%v'", kind)
|
||||
}
|
||||
// Using IsNil on reflect.Ptr variable is OK.
|
||||
if !rv.IsValid() || rv.IsNil() {
|
||||
|
Loading…
Reference in New Issue
Block a user