summaryrefslogtreecommitdiffstats
path: root/arch/arch.go
blob: d4a3e6b79ef69e050ac320771f7941ccc7c7a529 (plain)
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
// package arch contains mappings between the Golang architecture and
// the RPM architecture used by Fedora CoreOS and derivatives.
package arch

import "runtime"

type mapping struct {
	rpmArch string
	goArch  string
}

// If an architecture isn't defined here, we assume it's
// pass through.
var translations = []mapping{
	{
		rpmArch: "x86_64",
		goArch:  "amd64",
	},
	{
		rpmArch: "aarch64",
		goArch:  "arm64",
	},
}

// CurrentRpmArch returns the current architecture in RPM terms.
func CurrentRpmArch() string {
	return RpmArch(runtime.GOARCH)
}

// RpmArch translates a Go architecture to RPM.
func RpmArch(goarch string) string {
	for _, m := range translations {
		if m.goArch == goarch {
			return m.rpmArch
		}
	}
	return goarch
}

// GoArch translates an RPM architecture to Go.
func GoArch(rpmarch string) string {
	for _, m := range translations {
		if m.rpmArch == rpmarch {
			return m.goArch
		}
	}
	return rpmarch
}