2026 年的文章
可觀測性:三態健康檢查與 tracing 抽象層
gortex 的三態健康檢查比 up/down 多一個降級狀態,tracing 只依賴 Tracer 介面,OTel 當 adapter 接上,要產生 OTel span 得改用 adapter 自己的方法。
WebSocket Hub:Go 版 Actor 模型
gortex 的 WebSocket Hub 是 Go 版 actor 模型:狀態只由單一 goroutine 持有,外部透過 channel 送請求,用通訊取代鎖,慢消費者滿了就丟。
併發計數與韌性:sharded metrics 與 circuit breaker
gortex 用 FNV hash 把鎖拆成 16 片、高頻計數走 atomic,circuit breaker 是三態機,這裡用 atomic 與 mutex 比 channel 直接。
在 Cloudflare Pages 上替 Hugo 接 Decap CMS
實作記錄:Hugo 靜態站搭配 Decap CMS,透過 Cloudflare Pages Functions 處理 GitHub OAuth,支援中英雙語 collection。
零分配的秘密:Context pool 與 smartParams
gortex 路由零分配的三個手法:sync.Pool 重用 Context、[4]string 的 smartParams、內嵌 responseWriter,再用 benchmem 驗證。
Segment-trie 路由器:不靠正則的匹配
gortex 的 segment-trie 路由器不靠正則,每次請求只做字串切割加 map 查詢,不需回溯時比對成本 O(segments),Static、Param、Wildcard 依序比對並支援回溯。
Struct tag 宣告式路由:reflect 實戰
gortex 用 reflect 在啟動時掃 handler struct 的 tag 自動發現路由表,方法名決定 HTTP method,middleware 沿群組繼承,設定錯誤在啟動期就報錯。