-
Notifications
You must be signed in to change notification settings - Fork 0
/
listBinaries.go
57 lines (49 loc) 路 1.45 KB
/
listBinaries.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// listBinaries.go // This file implements the listBinaries function //>
package main
import (
"fmt"
"path/filepath"
"sort"
"strings"
)
// listBinariesCommand fetches and lists binary names from the given URL.
func listBinaries() ([]string, error) {
var allBinaries []string
var metadata []struct {
Name string `json:"Name"` // Consider both "name" and "Name" fields
NameAlt string `json:"name"`
}
// Fetch binaries from each metadata URL
for _, url := range MetadataURLs {
// Fetch metadata from the given URL
if err := fetchJSON(url, &metadata); err != nil {
return nil, fmt.Errorf("failed to fetch metadata from %s: %v", url, err)
}
// Extract binary names
for _, item := range metadata {
if item.Name != "" {
allBinaries = append(allBinaries, item.Name)
}
if item.NameAlt != "" {
allBinaries = append(allBinaries, item.NameAlt)
}
}
}
// Filter out excluded file types and file names
var filteredBinaries []string
for _, binary := range allBinaries {
ext := strings.ToLower(filepath.Ext(binary))
base := filepath.Base(binary)
if _, excluded := excludedFileTypes[ext]; !excluded {
if _, excludedName := excludedFileNames[base]; !excludedName {
filteredBinaries = append(filteredBinaries, binary)
}
}
}
// Remove duplicates
uniqueBinaries := removeDuplicates(filteredBinaries)
// Sort binaries alphabetically
sort.Strings(uniqueBinaries)
// Return the list of binaries
return uniqueBinaries, nil
}