暂存

tmp
This commit is contained in:
2024-05-09 16:35:21 +08:00
parent 3afa0d81bb
commit bcc1b51006
27 changed files with 1526 additions and 0 deletions

36
core/conns.go Normal file
View File

@@ -0,0 +1,36 @@
package core
import (
"fmt"
"log"
"sync"
"google.golang.org/grpc"
)
var conns = map[string]*grpc.ClientConn{}
var connsLock sync.Mutex
func AddConn(name string, conn *grpc.ClientConn) {
connsLock.Lock()
defer connsLock.Unlock()
if oldConn, ok := conns[name]; ok {
oldConn.Close()
}
conns[name] = conn
}
func PrintConns() {
connsLock.Lock()
defer connsLock.Unlock()
report := "Current connections:\n"
for name, conn := range conns {
report += fmt.Sprintf(" %s %s -> %s\n", conn.GetState(), name, conn.Target())
}
log.Print(report)
}