docs(gateway): gateway 剩余文件注释改中文(逐行 1:1,代码零字节改动)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

主人 2026-10-03 拍板「注释一律中文」;gateway 至此整包注释中文化完成(本会话共 3 批:
已推库 16 个文件 + 本批剩余文件)。
校验:机械校验(非注释改动行)= 空;剥注释后代码文本逐行比对全等(不一致文件数 0);
全树 go test ./... 58 包 ok / 0 FAIL;交叉编译绿。
This commit is contained in:
AskaEth committed 2026-10-03 22:28:25 +08:00
1 parent 91e8d7a029
commit 074ffc4ebf
73 files changed
+2529 -2529

No files matched your search

+16 -16
View File
@@ -15,9 +15,9 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/history"
)
// wsConn wraps one WebSocket connection. Writes are serialized through the
// buffered send channel drained by a single writePump, so the gorilla conn is
// only ever touched by one goroutine at a time.
// wsConn 包装一个 WebSocket 连接。写入经缓冲的 send
// 通道串行化,由单个 writePump 排空,因此 gorilla conn
// 在任一时刻只被一个 goroutine 触碰。
type wsConn struct {
conn *websocket.Conn
send chan []byte
@@ -27,9 +27,9 @@ type wsConn struct {
once sync.Once
}
// handleWS upgrades /ws/chat after authenticating the JWT from the query token or
// the Authorization header. A failed upgrade writes a 401 {error:...} before the
// handshake, so a browser/IM client sees a clean reject.
// handleWS 在校验来自查询 token 或 Authorization 头的 JWT 之后
// 升级 /ws/chat。升级失败会在握手前写出 401 {error:...},
// 使浏览器/IM 客户端看到干净的拒绝。
func (s *Server) handleWS(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
writeError(w, apperr.Wrap(apperr.ErrBadRequest, "bad_request", "websocket requires GET"))
@@ -59,7 +59,7 @@ func (s *Server) handleWS(w http.ResponseWriter, r *http.Request) {
go c.readPump()
}
// readPump reads client frames until the connection closes, routing each by type.
// readPump 读取客户端帧直到连接关闭,按类型路由每个帧。
func (c *wsConn) readPump() {
defer func() {
c.h.unregister(c)
@@ -87,8 +87,8 @@ func (c *wsConn) readPump() {
}
}
// writePump drains the send channel (and sends keepalive pings) until the
// connection closes. It is the only writer on the gorilla conn.
// writePump 排空 send 通道(并发送 keepalive ping)直到
// 连接关闭。它是 gorilla conn 上唯一的写入者。
func (c *wsConn) writePump() {
ticker := time.NewTicker(wsPingPeriod)
defer func() {
@@ -113,7 +113,7 @@ func (c *wsConn) writePump() {
}
}
// publishPublic publishes a bus event without any per-connection reply.
// publishPublic 发布一个 bus 事件,且不做任何按连接的回复。
func (c *wsConn) publishPublic(subject string, payload any) {
if c.h.bus == nil {
return
@@ -121,8 +121,8 @@ func (c *wsConn) publishPublic(subject string, payload any) {
_ = c.h.bus.Publish(context.Background(), subject, payload)
}
// shutdown closes the connection exactly once. It tolerates a nil *websocket.Conn
// so tests that build a fake connection can rely on a safe teardown.
// shutdown 恰好关闭连接一次。它容忍 nil 的 *websocket.Conn,
// 因此构建假连接的测试可以依赖安全的清理。
func (c *wsConn) shutdown() {
c.once.Do(func() {
close(c.done)
@@ -132,8 +132,8 @@ func (c *wsConn) shutdown() {
})
}
// enqueue queues a serialized frame, dropping it when a slow client's buffer is
// full so the producer never blocks.
// enqueue 把序列化后的帧入队,慢客户端缓冲满时丢弃它,
// 使生产者绝不阻塞。
func (c *wsConn) enqueue(b []byte) {
select {
case c.send <- b:
@@ -141,7 +141,7 @@ func (c *wsConn) enqueue(b []byte) {
}
}
// enqueueJSON serializes ev and queues it.
// enqueueJSON 序列化 ev 并把它入队。
func (c *wsConn) enqueueJSON(ev wsEvent) {
b, err := json.Marshal(ev)
if err != nil {
@@ -151,7 +151,7 @@ func (c *wsConn) enqueueJSON(ev wsEvent) {
c.enqueue(b)
}
// wsToken extracts the JWT from the ?token= query or the Authorization header.
// wsToken 从 ?token= 查询或 Authorization 头中提取 JWT。
func wsToken(r *http.Request) string {
if t := r.URL.Query().Get("token"); t != "" {
return t