-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslate.go
More file actions
30 lines (26 loc) · 758 Bytes
/
translate.go
File metadata and controls
30 lines (26 loc) · 758 Bytes
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
package platforms
// Translate parses a platform string from one ecosystem and formats it for another.
func Translate(from, to Ecosystem, s string) (string, error) {
p, err := Parse(from, s)
if err != nil {
return "", err
}
// When translating to an ecosystem that needs vendor/ABI info but the
// source ecosystem didn't provide it, fill in defaults.
if p.Vendor == "" {
p.Vendor = defaultVendor(p.OS)
}
if p.ABI == "" && p.OS == "linux" {
p.ABI = "gnu"
}
return Format(to, p)
}
// Normalize parses and re-formats a platform string within the same ecosystem,
// returning the preferred form.
func Normalize(eco Ecosystem, s string) (string, error) {
p, err := Parse(eco, s)
if err != nil {
return "", err
}
return Format(eco, p)
}