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

+14 -14
View File
@@ -10,9 +10,9 @@ import (
apperr "git.yeij.top/AskaEth/Cyrene_v2/internal/errors"
)
// cors sets the Access-Control-* headers for origins in the configured allow
// list and short-circuits OPTIONS preflight requests. An empty origin (same-origin
// or non-browser client) is passed through untouched.
// cors 为已配置允许列表中的来源设置 Access-Control-* 头,并
// 短路 OPTIONS 预检请求。空来源(同源或
// 非浏览器客户端)原样放行。
func (s *Server) cors(next http.Handler) http.Handler {
allowed, allowAll := s.allowedOrigins()
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -36,8 +36,8 @@ func (s *Server) cors(next http.Handler) http.Handler {
})
}
// allowedOrigins resolves the configured origin list into a lookup set plus an
// allow-all flag for the "*" wildcard.
// allowedOrigins 把已配置的来源列表解析成查找集合,外加针对
// "*" 通配符的允许全部标志。
func (s *Server) allowedOrigins() (map[string]bool, bool) {
list := s.cfg.AllowedOrigins
if len(list) == 0 {
@@ -55,8 +55,8 @@ func (s *Server) allowedOrigins() (map[string]bool, bool) {
return out, allowAll
}
// recover converts a panic in a downstream handler into a 500 {error:...}
// response instead of crashing the process, and logs the panic.
// recover 把下游 handler 中的 panic 转成 500 {error:...}
// 响应,而不是让进程崩溃,并记录该 panic。
func (s *Server) recover(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
@@ -69,7 +69,7 @@ func (s *Server) recover(next http.Handler) http.Handler {
})
}
// logging records one structured line per request (method, path, status, dur).
// logging 为每个请求记录一行结构化日志(method、path、status、dur)。
func (s *Server) logging(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
@@ -86,21 +86,21 @@ func (s *Server) logging(next http.Handler) http.Handler {
})
}
// statusRecorder captures the written status so the logging middleware can report
// it. It forwards the optional Hijacker/Flusher interfaces so the WebSocket
// upgrader (which requires http.Hijacker) and streaming handlers still work.
// statusRecorder 捕获写入的状态,使 logging 中间件能报告
// 它。它转发可选的 Hijacker/Flusher 接口,因此 WebSocket
// 升级器(要求 http.Hijacker)与流式 handler 仍能工作。
type statusRecorder struct {
http.ResponseWriter
status int
}
// WriteHeader records the status before delegating.
// WriteHeader 在委托之前记录状态。
func (r *statusRecorder) WriteHeader(code int) {
r.status = code
r.ResponseWriter.WriteHeader(code)
}
// Hijack forwards to the underlying writer when it supports connection hijacking.
// Hijack 在底层 writer 支持连接劫持时转发给它。
func (r *statusRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if hj, ok := r.ResponseWriter.(http.Hijacker); ok {
return hj.Hijack()
@@ -108,7 +108,7 @@ func (r *statusRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return nil, nil, fmt.Errorf("gateway: hijack unsupported by %T", r.ResponseWriter)
}
// Flush forwards to the underlying writer when it supports flushing.
// Flush 在底层 writer 支持 flush 时转发给它。
func (r *statusRecorder) Flush() {
if f, ok := r.ResponseWriter.(http.Flusher); ok {
f.Flush()