Refactor all plugins to functional options pattern#326
Draft
Copilot wants to merge 1 commit into
Draft
Conversation
Agent-Logs-Url: https://github.com/Loyalsoldier/geoip/sessions/e2b66c9a-3d01-490c-9b31-32109cfe4feb Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
Loyalsoldier
April 28, 2026 18:41
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All plugin constructors previously used direct struct instantiation with exported types, mixing JSON parsing, validation, and construction logic in a single
new*function. This refactors every plugin inplugin/subdirectories to match the functional options pattern established byplugin/singbox/srs_in.go/srs_out.go.Changes
Pattern applied uniformly across all plugins
New*(action, opts...)constructor accepting variadiclib.InputOption/lib.OutputOptionWith*()option functions per configurable field (with validation vialog.Fatalffor required/exclusive options, matching the reference)New*FromBytes(action, data)for JSON-based construction, called frominit()Shared-constructor plugins (maxmind, plaintext)
These packages share one struct across multiple registered types (e.g.
geoLite2CountryMMDBInservesmaxmindMMDB,dbipCountryMMDB,ipinfoCountryMMDB). Constructors and option functions takeiType/iDescas explicit parameters to carry type identity:Callers updated
lookup.goandmerge.go(which previously used struct literals with exported fields) are updated to use the new constructors.Files changed
plugin/mihomo:mrs_in.go,mrs_out.goplugin/v2ray:dat_in.go,dat_out.goplugin/special:cutter.go,lookup.go,private.go,stdin.go,stdout.go,test.goplugin/maxmind:common_in.go,common_out.go, all*_mmdb_{in,out}.go,maxmind_asn_csv_in.go,maxmind_country_csv_in.goplugin/plaintext:common_{in,out}.go,text_{in,out}.go,clash_{in,out}.go,surge_{in,out}.go,json_in.golookup.go,merge.go