|
@@ -57,11 +57,11 @@ func NewServer(args ...string) *Server {
|
|
ServerNumber++
|
|
ServerNumber++
|
|
}
|
|
}
|
|
s := &Server{
|
|
s := &Server{
|
|
- Config: Config,
|
|
|
|
- Env: map[string]interface{}{},
|
|
|
|
- Apps: map[string]*App{},
|
|
|
|
|
|
+ Config: Config,
|
|
|
|
+ Env: map[string]interface{}{},
|
|
|
|
+ Apps: map[string]*App{},
|
|
AppsNamePath: map[string]string{},
|
|
AppsNamePath: map[string]string{},
|
|
- Name: name,
|
|
|
|
|
|
+ Name: name,
|
|
}
|
|
}
|
|
Servers[s.Name] = s
|
|
Servers[s.Name] = s
|
|
|
|
|
|
@@ -171,6 +171,59 @@ func (s *Server) Process(w http.ResponseWriter, req *http.Request) {
|
|
}
|
|
}
|
|
|
|
|
|
// Run starts the web application and serves HTTP requests for s
|
|
// Run starts the web application and serves HTTP requests for s
|
|
|
|
+func (s *Server) RunBase(addr string, mux *http.ServeMux) {
|
|
|
|
+ addrs := strings.Split(addr, ":")
|
|
|
|
+ s.Config.Addr = addrs[0]
|
|
|
|
+ s.Config.Port, _ = strconv.Atoi(addrs[1])
|
|
|
|
+
|
|
|
|
+ s.initServer()
|
|
|
|
+
|
|
|
|
+ //mux := http.NewServeMux()
|
|
|
|
+ if s.Config.Profiler {
|
|
|
|
+ mux.Handle("/debug/pprof", http.HandlerFunc(pprof.Index))
|
|
|
|
+ mux.Handle("/debug/pprof/heap", pprof.Handler("heap"))
|
|
|
|
+ mux.Handle("/debug/pprof/block", pprof.Handler("block"))
|
|
|
|
+ mux.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
|
|
|
|
+ mux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
|
|
|
|
+
|
|
|
|
+ mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
|
|
|
|
+ mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
|
|
|
|
+ mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
|
|
|
|
+
|
|
|
|
+ mux.Handle("/debug/pprof/startcpuprof", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
+ StartCPUProfile()
|
|
|
|
+ }))
|
|
|
|
+ mux.Handle("/debug/pprof/stopcpuprof", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
+ StopCPUProfile()
|
|
|
|
+ }))
|
|
|
|
+ mux.Handle("/debug/pprof/memprof", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
+ runtime.GC()
|
|
|
|
+ runtimePprof.WriteHeapProfile(rw)
|
|
|
|
+ }))
|
|
|
|
+ mux.Handle("/debug/pprof/gc", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
+ PrintGCSummary(rw)
|
|
|
|
+ }))
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if c, err := XHook.Call("MuxHandle", mux); err == nil {
|
|
|
|
+ if ret := XHook.Value(c, 0); ret != nil {
|
|
|
|
+ mux = ret.(*http.ServeMux)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ mux.Handle("/", s)
|
|
|
|
+
|
|
|
|
+ s.Logger.Infof("http server is listening %s", addr)
|
|
|
|
+
|
|
|
|
+ l, err := net.Listen("tcp", addr)
|
|
|
|
+ if err != nil {
|
|
|
|
+ s.Logger.Error("ListenAndServe:", err)
|
|
|
|
+ }
|
|
|
|
+ s.l = l
|
|
|
|
+ err = http.Serve(s.l, mux)
|
|
|
|
+ s.l.Close()
|
|
|
|
+}
|
|
|
|
+
|
|
func (s *Server) Run(addr string) {
|
|
func (s *Server) Run(addr string) {
|
|
addrs := strings.Split(addr, ":")
|
|
addrs := strings.Split(addr, ":")
|
|
s.Config.Addr = addrs[0]
|
|
s.Config.Addr = addrs[0]
|