add domain support for domain of ghttp.Server

This commit is contained in:
John
2020-10-14 21:18:11 +08:00
parent 67fb626339
commit 82b531fbfb
2 changed files with 10 additions and 4 deletions

View File

@ -1,12 +1,13 @@
package main
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
func main() {
s := ghttp.GetServer()
s.EnablePProf()
s := g.Server()
s.Domain("localhost").EnablePProf()
s.BindHandler("/", func(r *ghttp.Request) {
r.Response.Writeln("哈喽世界!")
})

View File

@ -24,14 +24,19 @@ const (
// EnablePProf enables PProf feature for server.
func (s *Server) EnablePProf(pattern ...string) {
s.Domain(gDEFAULT_DOMAIN).EnablePProf(pattern...)
}
// EnablePProf enables PProf feature for server of specified domain.
func (d *Domain) EnablePProf(pattern ...string) {
p := gDEFAULT_PPROF_PATTERN
if len(pattern) > 0 && pattern[0] != "" {
p = pattern[0]
}
up := &utilPProf{}
_, _, uri, _ := s.parsePattern(p)
_, _, uri, _ := d.server.parsePattern(p)
uri = strings.TrimRight(uri, "/")
s.Group(uri, func(group *RouterGroup) {
d.Group(uri, func(group *RouterGroup) {
group.ALL("/*action", up.Index)
group.ALL("/cmdline", up.Cmdline)
group.ALL("/profile", up.Profile)