Skip to content

Refactor all plugins to functional options constructors#324

Draft
Codex wants to merge 7 commits into
refactor-pluginfrom
codex/refactor-plugins-functional-options
Draft

Refactor all plugins to functional options constructors#324
Codex wants to merge 7 commits into
refactor-pluginfrom
codex/refactor-plugins-functional-options

Conversation

@Codex

@Codex Codex AI commented Apr 28, 2026

Copy link
Copy Markdown

Refactors plugin implementations under plugin/* to consistently use the functional options pattern, aligned with the latest singbox plugin refactor. Preserves existing config semantics, including required/optional args and mutually-exclusive option relationships derived from the prior new**(action, data) constructors.

  • API Shape (All Plugins)

    • Standardize on New* constructors accepting ...lib.InputOption / ...lib.OutputOption
    • Add With* option setters for each plugin’s configurable fields
    • Move JSON config parsing into New*FromBytes(action, data) and wire Register*ConfigCreator to that entrypoint
  • Plugins Updated

    • plugin/mihomo: MRSIn, MRSOut
    • plugin/plaintext: text, json, clashRuleSet*, surgeRuleSet (input/output)
    • plugin/special: private, stdin, stdout, lookup, test, cutter
    • plugin/v2ray: GeoIPDatIn, GeoIPDatOut
    • plugin/maxmind: MMDB in/out (MaxMind/DB-IP/IPInfo) + GeoLite2 CSV (country/ASN)
  • Option Semantics Preserved

    • Keep the same validation gates and exclusivity rules (e.g. inputDir vs name/uri, JSON jsonPath required, defaults for paths/output dirs/names/extensions).
    • Maintain the existing JSON config keys and their meaning; changes are in constructor structure, not config schema.

Example (new construction style):

in := mihomo.NewMRSIn(
  lib.ActionAdd,
  mihomo.WithMRSNameAndURI("CN", "https://example/cn.mrs"),
  mihomo.WithMRSWantedList([]string{"CN", "US"}),
  mihomo.WithMRSOnlyIPType(lib.IPv6),
)

Codex AI and others added 7 commits April 28, 2026 17:40
Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
…t/cutter

Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
… plugins

Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants