Refactor: all plugins use functional option pattern - #358
Draft
Loyalsoldier with Claude wants to merge 5 commits into
Draft
Refactor: all plugins use functional option pattern#358Loyalsoldier with Claude wants to merge 5 commits into
Loyalsoldier with Claude wants to merge 5 commits into
Conversation
Agent-Logs-Url: https://github.com/Loyalsoldier/geoip/sessions/7c5acbd1-3a64-4061-9317-7c31caf27cb9 Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Loyalsoldier/geoip/sessions/7c5acbd1-3a64-4061-9317-7c31caf27cb9 Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Claude created this pull request from a session on behalf of
Loyalsoldier
July 29, 2026 14:06
View session
Owner
|
@copilot Review this PR, try to refine it and find potential bugs. |
Owner
|
@codex[agent] Review this PR, try to refine it and find potential bugs. |
Contributor
Reviewed and fixed the |
Contributor
Reviewed the PR at 9c73aee and rechecked the functional-option constructors, lookup source selection, and validation paths. I did not find additional regressions to patch; |
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.
Extends the functional option pattern introduced for
plugin/singbox(commit 182fdc0) to every converter underplugin/, so converters can be built programmatically with validated options instead of raw struct literals.Constructor shape
Each converter now exposes:
New*(action, opts ...lib.InputOption)/(..., opts ...lib.OutputOption)— applies options, validates, returns the converterNew*FromBytes(action, data []byte)— unmarshals JSON config and delegates toNew*With*functions for each individual fieldThe concrete structs are unexported (snake_case:
mrs_in,text_out,geolite2_asn_csv_in,cutter, …), so construction goes through the constructors.Validation
Required/optional derived from
configuration.md; invalid combinations abort vialog.FatalfinNew*:nameanduriare a singleWithNameAndURI(name, uri)option — specifying one without the other is rejectedinputDirrequired when neithernamenoruriis given (clashRuleSet,clashRuleSetClassical,json,mihomoMRS,singboxSRS,surgeRuleSet,text)v2rayGeoIPDatinput requiresuri;jsonrequiresjsonPath;stdinrequiresname;cutterrequiresremoveaction plus non-emptywantedList;lookupoutput requiressearchOption naming
Packages with a single in/out converter (
mihomo,v2ray,singbox) use the generic names. Packages with several converters prefix per converter to avoid collisions:maxmind:WithMMDBIn*,WithASNCSV*,WithCountryCSV*for inputs; genericWithOutput*+WithSourceMMDBURIfor the single outputspecial:WithCutter*,WithPrivateOnlyIPType,WithStdin*,WithStdout*,WithSearch/WithSearchListplaintext: all input types sharetext_inand all output types sharetext_out, so generic names work withiType/iDescpassed to the constructorDefaults
Type-dependent defaults (plaintext output dir/extension, maxmind default MMDB URI and CSV paths, maxmind output dir/name) are seeded in the constructor before options are applied; the matching
With*is a no-op on empty input, preserving current behavior for configs that omit them.Callers
Root
lookup.goandmerge.gonow build converters via the new constructors rather than struct literals.