2025-01-06 16:01:02 +08:00
|
|
|
|
package httpServer
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
"net/http"
|
|
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
|
|
"goutil/logUtil"
|
|
|
|
|
|
"goutil/logUtilPlus"
|
2025-01-23 16:12:49 +08:00
|
|
|
|
|
2025-01-06 16:01:02 +08:00
|
|
|
|
// "log"
|
|
|
|
|
|
"net/http/pprof"
|
|
|
|
|
|
|
|
|
|
|
|
config "common/configsYaml"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Start
|
|
|
|
|
|
// @description: 启动服务器
|
|
|
|
|
|
// parameter:
|
|
|
|
|
|
// @wg: WaitGroup对象
|
|
|
|
|
|
// return:
|
|
|
|
|
|
func Start(wg *sync.WaitGroup) {
|
|
|
|
|
|
defer func() {
|
|
|
|
|
|
wg.Done()
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
// 启动过程中不需要捕获异常
|
|
|
|
|
|
logUtilPlus.PrintAndWriteLog(logUtil.Info, fmt.Sprintf("Web服务器开始监听:%v", config.WebServerAddress))
|
|
|
|
|
|
|
|
|
|
|
|
// 启动Web服务器监听
|
|
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
|
|
mux.Handle("/", &selfDefineMux{})
|
|
|
|
|
|
mux.HandleFunc("/debug/pprof/", pprof.Index)
|
|
|
|
|
|
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
|
|
|
|
|
|
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
|
|
|
|
|
|
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
|
|
|
|
|
|
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
|
|
|
|
|
|
|
|
|
|
|
|
err := http.ListenAndServe(config.WebServerAddress, mux)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
panic(fmt.Errorf("ListenAndServe失败,错误信息为:%s", err))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|