From 1af42dfeb218dc99ea76b6cc4046ff007c32b5e0 Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Tue, 6 Aug 2024 10:40:21 +0800 Subject: Chore: sort output lists --- plugin/singbox/srs_out.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'plugin/singbox') 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) -- cgit v1.3.1