| 
									
										
										
										
											2015-10-18 00:50:51 +02:00
										 |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"strings" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type GoOS string | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ( | 
					
						
							|  |  |  | 	Windows   = GoOS("windows") | 
					
						
							|  |  |  | 	MacOS     = GoOS("darwin") | 
					
						
							|  |  |  | 	Linux     = GoOS("linux") | 
					
						
							| 
									
										
										
										
											2016-07-27 16:56:32 +02:00
										 |  |  | 	FreeBSD   = GoOS("freebsd") | 
					
						
							| 
									
										
										
										
											2016-10-17 14:41:54 +02:00
										 |  |  | 	OpenBSD   = GoOS("openbsd") | 
					
						
							| 
									
										
										
										
											2015-10-18 00:50:51 +02:00
										 |  |  | 	UnknownOS = GoOS("unknown") | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type GoArch string | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ( | 
					
						
							|  |  |  | 	X86         = GoArch("386") | 
					
						
							|  |  |  | 	Amd64       = GoArch("amd64") | 
					
						
							|  |  |  | 	Arm         = GoArch("arm") | 
					
						
							|  |  |  | 	Arm64       = GoArch("arm64") | 
					
						
							| 
									
										
										
										
											2016-02-20 12:32:42 +01:00
										 |  |  | 	Mips64      = GoArch("mips64") | 
					
						
							| 
									
										
										
										
											2015-10-18 00:50:51 +02:00
										 |  |  | 	UnknownArch = GoArch("unknown") | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func parseOS(rawOS string) GoOS { | 
					
						
							|  |  |  | 	osStr := strings.ToLower(rawOS) | 
					
						
							|  |  |  | 	if osStr == "windows" || osStr == "win" { | 
					
						
							|  |  |  | 		return Windows | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if osStr == "darwin" || osStr == "mac" || osStr == "macos" || osStr == "osx" { | 
					
						
							|  |  |  | 		return MacOS | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if osStr == "linux" || osStr == "debian" || osStr == "ubuntu" || osStr == "redhat" || osStr == "centos" { | 
					
						
							|  |  |  | 		return Linux | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-27 16:56:32 +02:00
										 |  |  | 	if osStr == "freebsd" { | 
					
						
							|  |  |  | 		return FreeBSD | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-10-17 14:41:54 +02:00
										 |  |  | 	if osStr == "openbsd" { | 
					
						
							|  |  |  | 		return OpenBSD | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-18 00:50:51 +02:00
										 |  |  | 	return UnknownOS | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func parseArch(rawArch string) GoArch { | 
					
						
							|  |  |  | 	archStr := strings.ToLower(rawArch) | 
					
						
							|  |  |  | 	if archStr == "x86" || archStr == "386" || archStr == "i386" { | 
					
						
							|  |  |  | 		return X86 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if archStr == "amd64" || archStr == "x86-64" || archStr == "x64" { | 
					
						
							|  |  |  | 		return Amd64 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if archStr == "arm" { | 
					
						
							|  |  |  | 		return Arm | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if archStr == "arm64" { | 
					
						
							|  |  |  | 		return Arm64 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-02-20 12:32:42 +01:00
										 |  |  | 	if archStr == "mips" || archStr == "mips64" { | 
					
						
							|  |  |  | 		return Mips64 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-18 00:50:51 +02:00
										 |  |  | 	return UnknownArch | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func getSuffix(os GoOS, arch GoArch) string { | 
					
						
							|  |  |  | 	suffix := "-custom" | 
					
						
							|  |  |  | 	switch os { | 
					
						
							|  |  |  | 	case Windows: | 
					
						
							|  |  |  | 		switch arch { | 
					
						
							|  |  |  | 		case X86: | 
					
						
							|  |  |  | 			suffix = "-windows-32" | 
					
						
							|  |  |  | 		case Amd64: | 
					
						
							|  |  |  | 			suffix = "-windows-64" | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	case MacOS: | 
					
						
							|  |  |  | 		suffix = "-macos" | 
					
						
							|  |  |  | 	case Linux: | 
					
						
							|  |  |  | 		switch arch { | 
					
						
							|  |  |  | 		case X86: | 
					
						
							|  |  |  | 			suffix = "-linux-32" | 
					
						
							|  |  |  | 		case Amd64: | 
					
						
							|  |  |  | 			suffix = "-linux-64" | 
					
						
							|  |  |  | 		case Arm: | 
					
						
							|  |  |  | 			suffix = "-linux-arm" | 
					
						
							|  |  |  | 		case Arm64: | 
					
						
							|  |  |  | 			suffix = "-linux-arm64" | 
					
						
							| 
									
										
										
										
											2016-02-20 12:32:42 +01:00
										 |  |  | 		case Mips64: | 
					
						
							|  |  |  | 			suffix = "-linux-mips64" | 
					
						
							| 
									
										
										
										
											2015-10-18 00:50:51 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-07-27 16:56:32 +02:00
										 |  |  | 	case FreeBSD: | 
					
						
							|  |  |  | 		switch arch { | 
					
						
							|  |  |  | 		case X86: | 
					
						
							|  |  |  | 			suffix = "-freebsd-32" | 
					
						
							|  |  |  | 		case Amd64: | 
					
						
							|  |  |  | 			suffix = "-freebsd-64" | 
					
						
							|  |  |  | 		case Arm: | 
					
						
							|  |  |  | 			suffix = "-freebsd-arm" | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-10-17 15:23:45 +02:00
										 |  |  | 	case OpenBSD: | 
					
						
							|  |  |  | 		switch arch { | 
					
						
							|  |  |  | 		case X86: | 
					
						
							|  |  |  | 			suffix = "-openbsd-32" | 
					
						
							|  |  |  | 		case Amd64: | 
					
						
							|  |  |  | 			suffix = "-openbsd-64" | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-10-18 00:50:51 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-10-17 15:23:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-18 00:50:51 +02:00
										 |  |  | 	return suffix | 
					
						
							|  |  |  | } |