ywxzm03 commented on code in PR #921: URL: https://github.com/apache/dubbo-go-pixiu/pull/921#discussion_r3200656557
########## skills/pixiu-filter-author/references/pluginregistry-howto.md: ########## @@ -0,0 +1,92 @@ +# `pkg/pluginregistry/registry.go` — The Single Boot Activator + +This file exists because Go's `init()` only runs for packages that are +**imported somewhere in the build graph**. Filters register themselves +in `init()`, so unless something imports their package, the `init()` +never runs and the registration never happens. `pluginregistry` is the +one file that imports every filter/adapter/listener/lb package for side +effects — a single central blank-import list — and `cmd/pixiu/` imports +`pluginregistry`. + +## Shape of the file + +```go +package pluginregistry + +import ( + _ "github.com/apache/dubbo-go-pixiu/pkg/adapter/dubboregistry" + _ "github.com/apache/dubbo-go-pixiu/pkg/adapter/llmregistry" + _ "github.com/apache/dubbo-go-pixiu/pkg/adapter/mcpserver" + // ... + _ "github.com/apache/dubbo-go-pixiu/pkg/cluster/loadbalancer/maglev" + // ... + _ "github.com/apache/dubbo-go-pixiu/pkg/filter/accesslog" + _ "github.com/apache/dubbo-go-pixiu/pkg/filter/cors" + // ... + _ "github.com/apache/dubbo-go-pixiu/pkg/filter/http/dubboproxy" + _ "github.com/apache/dubbo-go-pixiu/pkg/filter/http/httpproxy" + // ... + _ "github.com/apache/dubbo-go-pixiu/pkg/listener/http" + // ... +) +``` + +All imports are in one block. Entries are **alphabetical within each +logical group** — adapters, lb, retry, filter (top-level), +filter/http/, filter/network/, filter/auth/, listener. When adding, +keep the alphabetical order *within* the group your package belongs to. + +## How to add an import + +For a new filter at `pkg/filter/mynewfilter/`: + +```go +_ "github.com/apache/dubbo-go-pixiu/pkg/filter/mynewfilter" +``` + +Placement: in the top-level `pkg/filter/` group, alphabetically between +`_ "github.com/apache/dubbo-go-pixiu/pkg/filter/metric"` and +`_ "github.com/apache/dubbo-go-pixiu/pkg/filter/opa"` (or wherever +`mynewfilter` sorts). + +For a new proxy-style filter at `pkg/filter/http/mynewproxy/`: + +```go +_ "github.com/apache/dubbo-go-pixiu/pkg/filter/http/mynewproxy" +``` + +Placement: in the `pkg/filter/http/` group, alphabetically. + +## What happens if you forget + +- `go build ./...` — passes. +- `go test ./pkg/filter/mynewfilter/...` — passes. +- `./dubbo-go-pixiu gateway start -c configs/conf.yaml` — **fails at + config load** with `no filter found for name dgp.filter.http.mynew`. + +That boot-time error is the earliest signal. There is no compile-time +check because the blank import is literally an import for side effects +only. + +## Automating the check + +`scripts/gen-registry-import.sh` (in this skill) walks `pkg/filter/` and +`pkg/filter/http/`, grep's each package for `filter.RegisterHttpFilter` +or `filter.RegisterNetworkFilterPlugin`, and compares the resulting set +against the blank-import list. It prints the missing lines. It does NOT +edit the registry file — apply the diff by hand (this is a high-blast- +radius file; a human should read the insertion point). + +Run it as the last step of every filter PR. Review Comment: 感谢指出问题!我原本想着尽可能地提高准确率,但却疏忽了token成本,除了检查脚本,过多的references好像也没有太大的必要;我刚刚用分了三版skills跑了测试,最后对比综合评分,v1是保留参考references和scripts;v2是保留references,去除scripts;v3是将参考references和scripts都去除了;最后综合评分虽然是:v1 > v2 > v3,但差距甚微,v3的token消耗却只是v1的一半,综合考虑下,还是选择v3比较妥当 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
