发布

  • refactor(cmd): move plugin linkage behind cmd/defaults registration (#4897)

    frostbyte_neo 发布于 2026-08-25 05:38:55 +00:00 | 22 次提交 在此版本后已推送到 master

    • refactor(cmd): move plugin linkage behind cmd/defaults registration

    go-micro.dev/v6/cmd imported 10 plugin packages (NATS broker/registry/
    store/transport, Consul, etcd, RabbitMQ, Redis, Postgres, MySQL) so that
    --registry=etcd-style flags could resolve them. Because service
    constructs a Cmd unconditionally, every library binary linked all of it
    — a downstream measured 78 go-micro packages reachable from a minimal
    service, 41 of them plugin machinery for infrastructure the process
    never runs — along with their third-party clients and init() side
    effects.

    Move the plugin linkage behind registration:

    • cmd keeps only the zero-dependency in-core entries (memory/http
      broker, memory/mdns registry, memory store) in its Default* maps.
    • New cmd/defaults registers every plugin into those maps from init();
      the micro CLI blank-imports it, so CLI flag selection is unchanged.
    • service/profile keeps the Profile type and LocalProfile, and gains
      Register/Load; the NATS profile moves to service/profile/natsprofile,
      which self-registers (linked via cmd/defaults or a direct import).
    • Flag lookups that miss now say the plugin "is not linked into this
      binary: import go-micro.dev/v6/cmd/defaults" instead of a bare
      not-found.

    A minimal service binary now links 53 go-micro packages with zero
    plugin machinery and no NATS/Consul/etcd/Redis/SQL client deps (bbolt
    remains for the in-core file store).

    BREAKING: a library binary that relies on service.Init() resolving
    --registry/--broker/--store/--transport/--profile flag values to
    external plugins must add: import _ "go-micro.dev/v6/cmd/defaults".
    profile.NatsProfile moved to the natsprofile package.

    Reported by a downstream user (finding 2); finding 1 landed separately.

    • refactor(profile): guard the registry, clarify Load error, fix typo

    Review feedback: guard the profile map with a sync.RWMutex and reject
    empty names / nil constructors in Register (panic — the useful failure
    for init-time registration); make the unregistered-profile error cover
    the mistyped-name case as well as the missing-import case; rename
    splitNatsAdressList -> splitNatsAddressList.


    Co-authored-by: Claude noreply@anthropic.com

    下载附件