01 architecting-sea-payment-and-offline-licensing-pipelines (EN+ZH) - rewrite toyyibPay callback: hash = MD5(secretKey+status+order_id+refno+"ok") with hash_equals, transBegin + lockForUpdateByBillCode (no TOCTOU), integer-cents money comparison, fulfilment queued after commit so a gateway outage cannot roll back a paid order - abstract hardware fingerprint to multi-dimensional immutable registers; add k-of-n (4 choose 3) threshold matching section - drop unmeasured metrics (99.8% / 1.8s / 70%); fix duplicated 离线离线 typo 03 traefik-yaegi-plugin-package-name-trap (EN+ZH) - title: drop second-person "Your" - fix YAIEGI -> YAEGI code comment typo - add Go-spec root cause (hyphen is subtraction, go.mod decoupling vs Yaegi) - add .traefik.yml manifest contract paragraph - sanitize YAML thresholds as illustrative; add "where Yaegi stops being the right tool" boundary section - de-second-person the closing paragraph Consultant review pack v1.1 shipped separately (docx 05 = response ledger).
This commit is contained in:
1 parent
c0ea7ea066
commit
a7077a3a1d
4 files changed
+209
-46
No files matched your search
@@ -70,6 +70,12 @@ Traefik 会要求 Yaegi 在插件包中寻找并导出符合中间件契约的
|
||||
|
||||
在标准的 Go 语言工程中,模块路径与目录名经常带有连字符(如 `module github.com/hoelee/traefik-botfilter`),而源码文件首行通常声明不带前缀的合法标识符(如 `package botfilter`)。官方 Go 编译器(`gc`)通过模块导入路径可以完美绑定解析。
|
||||
|
||||
这里还有一层语言层面的根因:在 Go 中连字符 `-` 是减法运算符,因此 `package traefik-botfilter`
|
||||
不是「不常见」,而是不合语法、永远无法编译。标准工具链正是靠 `go.mod` 把带连字符的目录名/模块路径
|
||||
与文件内声明的标识符解耦的。Yaegi 不解析模块图,它从源码文本出发,先合成求值上下文,再在自己算出的
|
||||
命名空间里反射查找 `CreateConfig`——这条路径根本不读 `go.mod`,所以声明的包名必须与加载器算出的那个
|
||||
完全一致。
|
||||
|
||||
**但是,Yaegi 动态解释器并不走标准 Go 模块语义解析流程。**
|
||||
|
||||
Traefik 的动态插件加载器会直接从静态配置中 **`moduleName` 的最后一个路径段** 提取包标识符,并且**自动将所有的连字符(`-`)强制转换为下划线(`_`)**:
|
||||
@@ -162,4 +168,15 @@ http:
|
||||
2026-10-23T04:48:44Z INF Plugin loaded successfully module=github.com/hoelee/traefik-botfilter
|
||||
```
|
||||
|
||||
对于开发 Traefik 动态插件的工程师而言:**Go 官方编译器的通过并不代表动态运行时的认可。** 必须确保包名与模块路径最后一段的下划线转换规则完全一致,才能避免网关在生产启动时发生静默瘫痪。
|
||||
在 Traefik 动态插件工程里,**Go 官方编译器的通过只算赢了一半。** 包声明必须与模块路径清洗后的
|
||||
末段一致,`.traefik.yml` 的 import 又必须指向同一个模块——否则 Yaegi 会拒绝拉起网关,而报错里点名的
|
||||
那个符号,在每一轮本地测试里都明明存在。
|
||||
|
||||
## Yaegi 插件在什么情况下不再是正解
|
||||
|
||||
在每秒数千请求量级的边缘节点上,进程内解释型插件是最便宜的正解:不需要 Redis、不需要边车进程、
|
||||
不需要额外守护,拦截器与路由共享同一块内存。代价在两个地方兑现——解释执行比编译码慢,且插件的
|
||||
每一次分配都落在 Traefik 进程自己的堆上,于是 GC 压力随流量上升,而不是随规则复杂度上升。当单机
|
||||
吞吐进入数万 QPS 量级,或面对洪峰型扫描时,顺序必须反过来:先在代理之前丢包(CDN 侧边缘 WAF,或宿主机
|
||||
上的 CrowdSec 配合 nftables / eBPF),再让 Go 插件处理包过滤看不见的语义问题——头部形态、请求节流、
|
||||
分 IP 评分。
|
||||
Reference in new issue
Block a user