env.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package main
  2. import (
  3. "strings"
  4. )
  5. type GoOS string
  6. const (
  7. Windows = GoOS("windows")
  8. MacOS = GoOS("darwin")
  9. Linux = GoOS("linux")
  10. FreeBSD = GoOS("freebsd")
  11. OpenBSD = GoOS("openbsd")
  12. UnknownOS = GoOS("unknown")
  13. )
  14. type GoArch string
  15. const (
  16. X86 = GoArch("386")
  17. Amd64 = GoArch("amd64")
  18. Arm = GoArch("arm")
  19. Arm64 = GoArch("arm64")
  20. Mips64 = GoArch("mips64")
  21. UnknownArch = GoArch("unknown")
  22. )
  23. func parseOS(rawOS string) GoOS {
  24. osStr := strings.ToLower(rawOS)
  25. if osStr == "windows" || osStr == "win" {
  26. return Windows
  27. }
  28. if osStr == "darwin" || osStr == "mac" || osStr == "macos" || osStr == "osx" {
  29. return MacOS
  30. }
  31. if osStr == "linux" || osStr == "debian" || osStr == "ubuntu" || osStr == "redhat" || osStr == "centos" {
  32. return Linux
  33. }
  34. if osStr == "freebsd" {
  35. return FreeBSD
  36. }
  37. if osStr == "openbsd" {
  38. return OpenBSD
  39. }
  40. return UnknownOS
  41. }
  42. func parseArch(rawArch string) GoArch {
  43. archStr := strings.ToLower(rawArch)
  44. if archStr == "x86" || archStr == "386" || archStr == "i386" {
  45. return X86
  46. }
  47. if archStr == "amd64" || archStr == "x86-64" || archStr == "x64" {
  48. return Amd64
  49. }
  50. if archStr == "arm" {
  51. return Arm
  52. }
  53. if archStr == "arm64" {
  54. return Arm64
  55. }
  56. if archStr == "mips" || archStr == "mips64" {
  57. return Mips64
  58. }
  59. return UnknownArch
  60. }
  61. func getSuffix(os GoOS, arch GoArch) string {
  62. suffix := "-custom"
  63. switch os {
  64. case Windows:
  65. switch arch {
  66. case X86:
  67. suffix = "-windows-32"
  68. case Amd64:
  69. suffix = "-windows-64"
  70. }
  71. case MacOS:
  72. suffix = "-macos"
  73. case Linux:
  74. switch arch {
  75. case X86:
  76. suffix = "-linux-32"
  77. case Amd64:
  78. suffix = "-linux-64"
  79. case Arm:
  80. suffix = "-linux-arm"
  81. case Arm64:
  82. suffix = "-linux-arm64"
  83. case Mips64:
  84. suffix = "-linux-mips64"
  85. }
  86. case FreeBSD:
  87. switch arch {
  88. case X86:
  89. suffix = "-freebsd-32"
  90. case Amd64:
  91. suffix = "-freebsd-64"
  92. case Arm:
  93. suffix = "-freebsd-arm"
  94. }
  95. case OpenBSD:
  96. switch arch {
  97. case X86:
  98. suffix = "-openbsd-32"
  99. case Amd64:
  100. suffix = "-openbsd-64"
  101. }
  102. }
  103. return suffix
  104. }