summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorLoyalsoldier <[email protected]>2024-08-06 10:40:21 +0800
committerLoyalsoldier <[email protected]>2024-08-06 10:40:21 +0800
commit1af42dfeb218dc99ea76b6cc4046ff007c32b5e0 (patch)
treedb478bd0c5df5a5bd31b26ac8e93f9173ad51cf8 /plugin
parent18e14e610c29c745c6fb98002d352c19e1105b73 (diff)
Chore: sort output lists
Diffstat (limited to 'plugin')
-rw-r--r--plugin/maxmind/mmdb_out.go6
-rw-r--r--plugin/plaintext/text_out.go23
-rw-r--r--plugin/singbox/srs_out.go23
-rw-r--r--plugin/v2ray/dat_out.go23
4 files changed, 65 insertions, 10 deletions
diff --git a/plugin/maxmind/mmdb_out.go b/plugin/maxmind/mmdb_out.go
index 8bdaab20..5b838463 100644
--- a/plugin/maxmind/mmdb_out.go
+++ b/plugin/maxmind/mmdb_out.go
@@ -7,6 +7,7 @@ import (
"net"
"os"
"path/filepath"
+ "slices"
"strings"
"github.com/Loyalsoldier/geoip/lib"
@@ -159,7 +160,7 @@ func (m *mmdbOut) getEntryNameListInOrder(container lib.Container) []string {
}
}
- list := make([]string, 0, 200)
+ list := make([]string, 0, 300)
for entry := range container.Loop() {
name := entry.GetName()
_, found := overwriteMap[name]
@@ -169,6 +170,9 @@ func (m *mmdbOut) getEntryNameListInOrder(container lib.Container) []string {
list = append(list, name)
}
+ // Sort the lists
+ slices.Sort(list)
+
// Make sure the names in overwriteList are written at last
list = append(list, overwriteList...)
diff --git a/plugin/plaintext/text_out.go b/plugin/plaintext/text_out.go
index 10ad6143..bc8f904e 100644
--- a/plugin/plaintext/text_out.go
+++ b/plugin/plaintext/text_out.go
@@ -3,6 +3,7 @@ package plaintext
import (
"encoding/json"
"log"
+ "slices"
"strings"
"github.com/Loyalsoldier/geoip/lib"
@@ -36,16 +37,29 @@ func (t *textOut) GetDescription() string {
func (t *textOut) Output(container lib.Container) error {
// Filter want list
- wantList := make(map[string]bool)
+ wantList := make([]string, 0, 50)
for _, want := range t.Want {
if want = strings.ToUpper(strings.TrimSpace(want)); want != "" {
- wantList[want] = true
+ wantList = append(wantList, want)
}
}
switch len(wantList) {
case 0:
+ list := make([]string, 0, 300)
for entry := range container.Loop() {
+ list = append(list, entry.GetName())
+ }
+
+ // Sort the list
+ slices.Sort(list)
+
+ for _, name := range list {
+ entry, found := container.GetEntry(name)
+ if !found {
+ log.Printf("❌ entry %s not found", name)
+ continue
+ }
data, err := t.marshalBytes(entry)
if err != nil {
return err
@@ -57,7 +71,10 @@ func (t *textOut) Output(container lib.Container) error {
}
default:
- for name := range wantList {
+ // Sort the list
+ slices.Sort(wantList)
+
+ for _, name := range wantList {
entry, found := container.GetEntry(name)
if !found {
log.Printf("❌ entry %s not found", name)
diff --git a/plugin/singbox/srs_out.go b/plugin/singbox/srs_out.go
index 7adfa579..7637d200 100644
--- a/plugin/singbox/srs_out.go
+++ b/plugin/singbox/srs_out.go
@@ -6,6 +6,7 @@ import (
"log"
"os"
"path/filepath"
+ "slices"
"strings"
"github.com/Loyalsoldier/geoip/lib"
@@ -82,23 +83,39 @@ func (s *srsOut) GetDescription() string {
func (s *srsOut) Output(container lib.Container) error {
// Filter want list
- wantList := make(map[string]bool)
+ wantList := make([]string, 0, 50)
for _, want := range s.Want {
if want = strings.ToUpper(strings.TrimSpace(want)); want != "" {
- wantList[want] = true
+ wantList = append(wantList, want)
}
}
switch len(wantList) {
case 0:
+ list := make([]string, 0, 300)
for entry := range container.Loop() {
+ list = append(list, entry.GetName())
+ }
+
+ // Sort the list
+ slices.Sort(list)
+
+ for _, name := range list {
+ entry, found := container.GetEntry(name)
+ if !found {
+ log.Printf("❌ entry %s not found", name)
+ continue
+ }
if err := s.run(entry); err != nil {
return err
}
}
default:
- for name := range wantList {
+ // Sort the list
+ slices.Sort(wantList)
+
+ for _, name := range wantList {
entry, found := container.GetEntry(name)
if !found {
log.Printf("❌ entry %s not found", name)
diff --git a/plugin/v2ray/dat_out.go b/plugin/v2ray/dat_out.go
index 46e3baa2..0dd9e23b 100644
--- a/plugin/v2ray/dat_out.go
+++ b/plugin/v2ray/dat_out.go
@@ -94,19 +94,33 @@ func (g *geoIPDatOut) GetDescription() string {
func (g *geoIPDatOut) Output(container lib.Container) error {
// Filter want list
- wantList := make(map[string]bool)
+ wantList := make([]string, 0, 50)
for _, want := range g.Want {
if want = strings.ToUpper(strings.TrimSpace(want)); want != "" {
- wantList[want] = true
+ wantList = append(wantList, want)
}
}
geoIPList := new(router.GeoIPList)
geoIPList.Entry = make([]*router.GeoIP, 0, 300)
updated := false
+
switch len(wantList) {
case 0:
+ list := make([]string, 0, 300)
for entry := range container.Loop() {
+ list = append(list, entry.GetName())
+ }
+
+ // Sort the list
+ sort.Strings(list)
+
+ for _, name := range list {
+ entry, found := container.GetEntry(name)
+ if !found {
+ log.Printf("❌ entry %s not found", name)
+ continue
+ }
geoIP, err := g.generateGeoIP(entry)
if err != nil {
return err
@@ -128,7 +142,10 @@ func (g *geoIPDatOut) Output(container lib.Container) error {
}
default:
- for name := range wantList {
+ // Sort the list
+ sort.Strings(wantList)
+
+ for _, name := range wantList {
entry, found := container.GetEntry(name)
if !found {
log.Printf("❌ entry %s not found", name)