summaryrefslogtreecommitdiffstats
path: root/arch/arch.go
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arch.go')
-rw-r--r--arch/arch.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/arch/arch.go b/arch/arch.go
new file mode 100644
index 0000000..d4a3e6b
--- /dev/null
+++ b/arch/arch.go
@@ -0,0 +1,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
+}