Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package initMgr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"goutil/debugUtil"
|
||||
"goutil/logUtil"
|
||||
)
|
||||
|
||||
// 初始化成功对象
|
||||
type InitSuccess struct {
|
||||
name string
|
||||
registerMap map[string]chan bool
|
||||
mutex sync.RWMutex
|
||||
}
|
||||
|
||||
// 注册需要被通知的对象
|
||||
// name:唯一标识
|
||||
// ch:用于通知的通道
|
||||
func (this *InitSuccess) Register(name string, ch chan bool) {
|
||||
this.mutex.Lock()
|
||||
defer this.mutex.Unlock()
|
||||
|
||||
if _, exists := this.registerMap[name]; exists {
|
||||
panic(fmt.Errorf("InitSuccess.Register-%s-%s已经存在,请检查", this.name, name))
|
||||
}
|
||||
|
||||
this.registerMap[name] = ch
|
||||
|
||||
logUtil.DebugLog(fmt.Sprintf("InitSuccess.Register-%s,当前共有%d个注册", this.name, len(this.registerMap)))
|
||||
}
|
||||
|
||||
// 取消启动成功通知注册
|
||||
// name:唯一标识
|
||||
func (this *InitSuccess) Unregister(name string) {
|
||||
this.mutex.Lock()
|
||||
defer this.mutex.Unlock()
|
||||
|
||||
delete(this.registerMap, name)
|
||||
}
|
||||
|
||||
// 通知所有已注册的对象
|
||||
func (this *InitSuccess) Notify() {
|
||||
this.mutex.RLock()
|
||||
defer this.mutex.RUnlock()
|
||||
|
||||
for name, ch := range this.registerMap {
|
||||
ch <- true
|
||||
msg := fmt.Sprintf("通知:%s-%s初始化成功", this.name, name)
|
||||
debugUtil.Println(msg)
|
||||
logUtil.DebugLog(msg)
|
||||
}
|
||||
}
|
||||
|
||||
// 创建初始化成功对象
|
||||
func NewInitSuccess(name string) *InitSuccess {
|
||||
return &InitSuccess{
|
||||
name: name,
|
||||
registerMap: make(map[string]chan bool),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package webServer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"goutil/logUtil"
|
||||
"goutil/logUtilPlus"
|
||||
"net/http/pprof"
|
||||
|
||||
config "common/configsYaml"
|
||||
)
|
||||
|
||||
// Start
|
||||
// @description: 启动服务器
|
||||
// parameter:
|
||||
// @wg: WaitGroup对象
|
||||
// return:
|
||||
func Start(wg *sync.WaitGroup) {
|
||||
defer func() {
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
// 启动过程中不需要捕获异常
|
||||
logUtilPlus.PrintAndWriteLog(logUtil.Warn, fmt.Sprintf("Web服务器开始监听:%v", config.ConfigYaml.Root.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.ConfigYaml.Root.WebServerAddress, mux)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("ListenAndServe失败,错误信息为:%s", err))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user