Skip to content

Commit 522ef5c

Browse files
committed
refactor(builder): use map lookup for archive type detection
- Extract archiveExtensions map for suffix-to-type mapping - Replace 14-line switch statement with map iteration - Makes extension mappings explicit and easily extensible
1 parent f45cdcf commit 522ef5c

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

internal/builder/library.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,26 @@ func (lib *Library) ShouldBuild() bool {
4747
return slices.Contains(lib.Platform, runtime.GOOS)
4848
}
4949

50+
// archiveExtensions maps file suffixes to canonical archive type names.
51+
var archiveExtensions = map[string]string{
52+
".tar.gz": "tar.gz",
53+
".tgz": "tar.gz",
54+
".tar.bz2": "tar.bz2",
55+
".tbz2": "tar.bz2",
56+
".tar.xz": "tar.xz",
57+
".txz": "tar.xz",
58+
".zip": "zip",
59+
}
60+
5061
// ArchiveType derives the archive type from the URL
5162
func (lib *Library) ArchiveType() string {
5263
url := strings.ToLower(lib.URL)
53-
switch {
54-
case strings.HasSuffix(url, ".tar.gz"), strings.HasSuffix(url, ".tgz"):
55-
return "tar.gz"
56-
case strings.HasSuffix(url, ".tar.bz2"), strings.HasSuffix(url, ".tbz2"):
57-
return "tar.bz2"
58-
case strings.HasSuffix(url, ".tar.xz"), strings.HasSuffix(url, ".txz"):
59-
return "tar.xz"
60-
case strings.HasSuffix(url, ".zip"):
61-
return "zip"
62-
default:
63-
return ""
64+
for ext, archiveType := range archiveExtensions {
65+
if strings.HasSuffix(url, ext) {
66+
return archiveType
67+
}
6468
}
69+
return ""
6570
}
6671

6772
// Build performs the complete build process for this library

0 commit comments

Comments
 (0)