diff --git a/net/ghttp/ghttp_request.go b/net/ghttp/ghttp_request.go index 3c0e244f6..f340f5859 100644 --- a/net/ghttp/ghttp_request.go +++ b/net/ghttp/ghttp_request.go @@ -33,7 +33,7 @@ type Request struct { Router *Router // Matched Router for this request. Note that it's not available in HOOK handler. EnterTime int64 // Request starting time in microseconds. LeaveTime int64 // Request ending time in microseconds. - Middleware *Middleware // Middleware manager. + Middleware *middleware // Middleware manager. StaticFile *StaticFile // Static file object for static file serving. context context.Context // Custom context for internal usage purpose. handlers []*handlerParsedItem // All matched handlers containing handler, hook and middleware for this request. @@ -75,7 +75,7 @@ func newRequest(s *Server, r *http.Request, w http.ResponseWriter) *Request { request.Cookie = GetCookie(request) request.Session = s.sessionManager.New(request.GetSessionId()) request.Response.Request = request - request.Middleware = &Middleware{ + request.Middleware = &middleware{ request: request, } // Custom session id creating function. diff --git a/net/ghttp/ghttp_request_middleware.go b/net/ghttp/ghttp_request_middleware.go index 6ddcde54e..caa0e0bb0 100644 --- a/net/ghttp/ghttp_request_middleware.go +++ b/net/ghttp/ghttp_request_middleware.go @@ -14,8 +14,8 @@ import ( "github.com/gogf/gf/util/gutil" ) -// Middleware is the plugin for request workflow management. -type Middleware struct { +// middleware is the plugin for request workflow management. +type middleware struct { served bool // Is the request served, which is used for checking response status 404. request *Request // The request object pointer. handlerIndex int // Index number for executing sequence purpose for handler items. @@ -24,7 +24,7 @@ type Middleware struct { // Next calls the next workflow handler. // It's an important function controlling the workflow of the server request execution. -func (m *Middleware) Next() { +func (m *middleware) Next() { var item *handlerParsedItem var loop = true for loop { diff --git a/net/ghttp/ghttp_server_pprof.go b/net/ghttp/ghttp_server_pprof.go index bcd8588bf..dc63a6a74 100644 --- a/net/ghttp/ghttp_server_pprof.go +++ b/net/ghttp/ghttp_server_pprof.go @@ -18,9 +18,18 @@ import ( type utilPProf struct{} const ( - defaultPProfPattern = "/debug/pprof" + defaultPProfServerName = "pprof-server" + defaultPProfPattern = "/debug/pprof" ) +// StartPProfServer starts and runs a new server for pprof. +func StartPProfServer(port int, pattern ...string) { + s := GetServer(defaultPProfServerName) + s.EnablePProf() + s.SetPort(port) + s.Run() +} + // EnablePProf enables PProf feature for server. func (s *Server) EnablePProf(pattern ...string) { s.Domain(defaultDomainName).EnablePProf(pattern...) @@ -56,13 +65,18 @@ func (p *utilPProf) Index(r *Request) { buffer, _ := gview.ParseContent(`
-| {{.Count}} | {{.Name}}{{end}} + {{range .profiles}} + |
| {{.Count}} | +{{.Name}} | +