mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
improve package ghttp
This commit is contained in:
@ -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.
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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(`
|
||||
<html>
|
||||
<head>
|
||||
<title>gf ghttp pprof</title>
|
||||
<title>GoFrame PProf</title>
|
||||
</head>
|
||||
{{$uri := .uri}}
|
||||
<body>
|
||||
profiles:<br>
|
||||
<table>
|
||||
{{range .profiles}}<tr><td align=right>{{.Count}}<td><a href="{{$uri}}{{.Name}}?debug=1">{{.Name}}</a>{{end}}
|
||||
{{range .profiles}}
|
||||
<tr>
|
||||
<td align=right>{{.Count}}</td>
|
||||
<td><a href="{{$uri}}{{.Name}}?debug=1">{{.Name}}</a></td>
|
||||
<tr>
|
||||
{{end}}
|
||||
</table>
|
||||
<br><a href="{{$uri}}goroutine?debug=2">full goroutine stack dump</a><br>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user