package godef import ( "hkdj-web-server/pub/common/log" "hkdj-web-server/pub/common/tgbot" "runtime" ) func Go(f func()) { //atomic.AddInt64(&routineCount, 1) go func() { defer func() { //atomic.AddInt64(&routineCount, -1) if r := recover(); r != nil { buf := make([]byte, 2048) length := runtime.Stack(buf, false) info := string(buf[:length]) log.Error("cat a unkown excetion", log.Any("excetion :", info), log.Any("e", r)) //发送tg消息 msg := "goroutine crash,the stack:\n" + info tgbot.SendToProgram("程序异常", msg) } }() f() }() }