diff options
| author | Loyalsoldier <[email protected]> | 2024-10-31 10:51:58 +0800 |
|---|---|---|
| committer | Loyalsoldier <[email protected]> | 2024-10-31 11:21:57 +0800 |
| commit | 883184cbdc5fff0763c56aae7b08b0605dc08a9b (patch) | |
| tree | b1def962ecffe4c2d4be37e77597dd4772ae3e1f /plugin/v2ray | |
| parent | 1e26c9803d42d3601c75c4db2ee3ff565b6388d8 (diff) | |
Feat: export input & output converters
Diffstat (limited to 'plugin/v2ray')
| -rw-r--r-- | plugin/v2ray/dat_in.go | 34 | ||||
| -rw-r--r-- | plugin/v2ray/dat_out.go | 34 |
2 files changed, 34 insertions, 34 deletions
diff --git a/plugin/v2ray/dat_in.go b/plugin/v2ray/dat_in.go index 37d8bb5a..af306600 100644 --- a/plugin/v2ray/dat_in.go +++ b/plugin/v2ray/dat_in.go @@ -14,16 +14,16 @@ import ( ) const ( - typeGeoIPdatIn = "v2rayGeoIPDat" - descGeoIPdatIn = "Convert V2Ray GeoIP dat to other formats" + TypeGeoIPdatIn = "v2rayGeoIPDat" + DescGeoIPdatIn = "Convert V2Ray GeoIP dat to other formats" ) func init() { - lib.RegisterInputConfigCreator(typeGeoIPdatIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + lib.RegisterInputConfigCreator(TypeGeoIPdatIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { return newGeoIPDatIn(action, data) }) - lib.RegisterInputConverter(typeGeoIPdatIn, &geoIPDatIn{ - Description: descGeoIPdatIn, + lib.RegisterInputConverter(TypeGeoIPdatIn, &GeoIPDatIn{ + Description: DescGeoIPdatIn, }) } @@ -41,7 +41,7 @@ func newGeoIPDatIn(action lib.Action, data json.RawMessage) (lib.InputConverter, } if tmp.URI == "" { - return nil, fmt.Errorf("❌ [type %s | action %s] uri must be specified in config", typeGeoIPdatIn, action) + return nil, fmt.Errorf("❌ [type %s | action %s] uri must be specified in config", TypeGeoIPdatIn, action) } // Filter want list @@ -52,17 +52,17 @@ func newGeoIPDatIn(action lib.Action, data json.RawMessage) (lib.InputConverter, } } - return &geoIPDatIn{ - Type: typeGeoIPdatIn, + return &GeoIPDatIn{ + Type: TypeGeoIPdatIn, Action: action, - Description: descGeoIPdatIn, + Description: DescGeoIPdatIn, URI: tmp.URI, Want: wantList, OnlyIPType: tmp.OnlyIPType, }, nil } -type geoIPDatIn struct { +type GeoIPDatIn struct { Type string Action lib.Action Description string @@ -71,19 +71,19 @@ type geoIPDatIn struct { OnlyIPType lib.IPType } -func (g *geoIPDatIn) GetType() string { +func (g *GeoIPDatIn) GetType() string { return g.Type } -func (g *geoIPDatIn) GetAction() lib.Action { +func (g *GeoIPDatIn) GetAction() lib.Action { return g.Action } -func (g *geoIPDatIn) GetDescription() string { +func (g *GeoIPDatIn) GetDescription() string { return g.Description } -func (g *geoIPDatIn) Input(container lib.Container) (lib.Container, error) { +func (g *GeoIPDatIn) Input(container lib.Container) (lib.Container, error) { entries := make(map[string]*lib.Entry) var err error @@ -128,7 +128,7 @@ func (g *geoIPDatIn) Input(container lib.Container) (lib.Container, error) { return container, nil } -func (g *geoIPDatIn) walkLocalFile(path string, entries map[string]*lib.Entry) error { +func (g *GeoIPDatIn) walkLocalFile(path string, entries map[string]*lib.Entry) error { file, err := os.Open(path) if err != nil { return err @@ -142,7 +142,7 @@ func (g *geoIPDatIn) walkLocalFile(path string, entries map[string]*lib.Entry) e return nil } -func (g *geoIPDatIn) walkRemoteFile(url string, entries map[string]*lib.Entry) error { +func (g *GeoIPDatIn) walkRemoteFile(url string, entries map[string]*lib.Entry) error { resp, err := http.Get(url) if err != nil { return err @@ -160,7 +160,7 @@ func (g *geoIPDatIn) walkRemoteFile(url string, entries map[string]*lib.Entry) e return nil } -func (g *geoIPDatIn) generateEntries(reader io.Reader, entries map[string]*lib.Entry) error { +func (g *GeoIPDatIn) generateEntries(reader io.Reader, entries map[string]*lib.Entry) error { geoipBytes, err := io.ReadAll(reader) if err != nil { return err diff --git a/plugin/v2ray/dat_out.go b/plugin/v2ray/dat_out.go index 3b120277..3e1cdbda 100644 --- a/plugin/v2ray/dat_out.go +++ b/plugin/v2ray/dat_out.go @@ -16,8 +16,8 @@ import ( ) const ( - typeGeoIPdatOut = "v2rayGeoIPDat" - descGeoIPdatOut = "Convert data to V2Ray GeoIP dat format" + TypeGeoIPdatOut = "v2rayGeoIPDat" + DescGeoIPdatOut = "Convert data to V2Ray GeoIP dat format" ) var ( @@ -26,11 +26,11 @@ var ( ) func init() { - lib.RegisterOutputConfigCreator(typeGeoIPdatOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { + lib.RegisterOutputConfigCreator(TypeGeoIPdatOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { return newGeoIPDat(action, data) }) - lib.RegisterOutputConverter(typeGeoIPdatOut, &geoIPDatOut{ - Description: descGeoIPdatOut, + lib.RegisterOutputConverter(TypeGeoIPdatOut, &GeoIPDatOut{ + Description: DescGeoIPdatOut, }) } @@ -58,10 +58,10 @@ func newGeoIPDat(action lib.Action, data json.RawMessage) (lib.OutputConverter, tmp.OutputDir = defaultOutputDir } - return &geoIPDatOut{ - Type: typeGeoIPdatOut, + return &GeoIPDatOut{ + Type: TypeGeoIPdatOut, Action: action, - Description: descGeoIPdatOut, + Description: DescGeoIPdatOut, OutputName: tmp.OutputName, OutputDir: tmp.OutputDir, Want: tmp.Want, @@ -71,7 +71,7 @@ func newGeoIPDat(action lib.Action, data json.RawMessage) (lib.OutputConverter, }, nil } -type geoIPDatOut struct { +type GeoIPDatOut struct { Type string Action lib.Action Description string @@ -83,19 +83,19 @@ type geoIPDatOut struct { OnlyIPType lib.IPType } -func (g *geoIPDatOut) GetType() string { +func (g *GeoIPDatOut) GetType() string { return g.Type } -func (g *geoIPDatOut) GetAction() lib.Action { +func (g *GeoIPDatOut) GetAction() lib.Action { return g.Action } -func (g *geoIPDatOut) GetDescription() string { +func (g *GeoIPDatOut) GetDescription() string { return g.Description } -func (g *geoIPDatOut) Output(container lib.Container) error { +func (g *GeoIPDatOut) Output(container lib.Container) error { geoIPList := new(GeoIPList) geoIPList.Entry = make([]*GeoIP, 0, 300) updated := false @@ -145,7 +145,7 @@ func (g *geoIPDatOut) Output(container lib.Container) error { return nil } -func (g *geoIPDatOut) filterAndSortList(container lib.Container) []string { +func (g *GeoIPDatOut) filterAndSortList(container lib.Container) []string { excludeMap := make(map[string]bool) for _, exclude := range g.Exclude { if exclude = strings.ToUpper(strings.TrimSpace(exclude)); exclude != "" { @@ -181,7 +181,7 @@ func (g *geoIPDatOut) filterAndSortList(container lib.Container) []string { return list } -func (g *geoIPDatOut) generateGeoIP(entry *lib.Entry) (*GeoIP, error) { +func (g *GeoIPDatOut) generateGeoIP(entry *lib.Entry) (*GeoIP, error) { var entryCidr []netip.Prefix var err error switch g.OnlyIPType { @@ -215,13 +215,13 @@ func (g *geoIPDatOut) generateGeoIP(entry *lib.Entry) (*GeoIP, error) { } // Sort by country code to make reproducible builds -func (g *geoIPDatOut) sort(list *GeoIPList) { +func (g *GeoIPDatOut) sort(list *GeoIPList) { sort.SliceStable(list.Entry, func(i, j int) bool { return list.Entry[i].CountryCode < list.Entry[j].CountryCode }) } -func (g *geoIPDatOut) writeFile(filename string, geoIPBytes []byte) error { +func (g *GeoIPDatOut) writeFile(filename string, geoIPBytes []byte) error { if err := os.MkdirAll(g.OutputDir, 0755); err != nil { return err } |
