feat: migrate to golang
This commit is contained in:
61
internal/core/platform.go
Normal file
61
internal/core/platform.go
Normal file
@ -0,0 +1,61 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// binaryNames maps GOOS -> GOARCH -> mihomo release asset base name.
|
||||
// Mirrors core_manager.py's platform_map (core_manager.py:38-55). Unlike the
|
||||
// Python version, no separate arch-normalization table is needed since
|
||||
// runtime.GOARCH already reports "amd64"/"386"/"arm64"/"arm".
|
||||
var binaryNames = map[string]map[string]string{
|
||||
"windows": {
|
||||
"amd64": "mihomo-windows-amd64",
|
||||
"386": "mihomo-windows-386",
|
||||
"arm64": "mihomo-windows-arm64",
|
||||
"arm": "mihomo-windows-arm32v7",
|
||||
},
|
||||
"linux": {
|
||||
"amd64": "mihomo-linux-amd64",
|
||||
"386": "mihomo-linux-386",
|
||||
"arm64": "mihomo-linux-arm64",
|
||||
"arm": "mihomo-linux-armv7",
|
||||
},
|
||||
"darwin": {
|
||||
"amd64": "mihomo-darwin-amd64",
|
||||
"arm64": "mihomo-darwin-arm64",
|
||||
},
|
||||
}
|
||||
|
||||
// platformInfo returns (system, arch, binaryNameBase), or ok=false if the
|
||||
// current platform/arch combination is unsupported.
|
||||
func platformInfo() (system, arch, binaryName string, ok bool) {
|
||||
system = runtime.GOOS
|
||||
arch = runtime.GOARCH
|
||||
|
||||
archs, systemSupported := binaryNames[system]
|
||||
if !systemSupported {
|
||||
return "", "", "", false
|
||||
}
|
||||
name, archSupported := archs[arch]
|
||||
if !archSupported {
|
||||
return "", "", "", false
|
||||
}
|
||||
return system, arch, name, true
|
||||
}
|
||||
|
||||
// binaryPath returns the local path where the mihomo executable for the
|
||||
// current platform is (or will be) stored.
|
||||
func binaryPath(binDir string) string {
|
||||
system, arch, _, ok := platformInfo()
|
||||
if !ok {
|
||||
system, arch = runtime.GOOS, runtime.GOARCH
|
||||
}
|
||||
suffix := "-" + system + "-" + arch
|
||||
name := "mihomo" + suffix
|
||||
if system == "windows" {
|
||||
name += ".exe"
|
||||
}
|
||||
return filepath.Join(binDir, name)
|
||||
}
|
||||
Reference in New Issue
Block a user