summaryrefslogtreecommitdiff
path: root/plugin/plaintext
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/plaintext
parent18e14e610c29c745c6fb98002d352c19e1105b73 (diff)
Chore: sort output lists
Diffstat (limited to 'plugin/plaintext')
-rw-r--r--plugin/plaintext/text_out.go23
1 files changed, 20 insertions, 3 deletions
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)