go-distroyer | 跨平台操作系统信息包 
go-distroyer软件包提供了多平台支持,使得在代码中进行分发检查变得容易。
安装
go get -u "github.com/zekiahmetbayar/go-distroyer"
使用方法
package main
import "github.com/zekiahmetbayar/go-distroyer"
func main() {
// Returns the client's processor architecture
// ex. x64, arm64...
arch, err := distroyer.Arch()
if err != nil {
log.Fatalf("error when getting arch: %s", err.Error())
}
fmt.Printf("Arch: %s\n", arch)
// Returns the codename of the client's distribution
// ex. jammy, focal...
codename, err := distroyer.Codename()
if err != nil {
log.Fatalf("error when getting codename: %s", err.Error())
}
fmt.Printf("Codename: %s\n", codename)
// Returns the id like of the client's distribution
// ex. debian, fedora, rhel...
like, err := distroyer.Like()
if err != nil {
log.Fatalf("error when getting platform like: %s", err.Error())
}
fmt.Printf("Like: %s\n", like)
// Returns the pretty name of the client's distribution
// ex. Ubuntu 20.04 LTS (Focal Fossa)
pretty, err := distroyer.PrettyName()
if err != nil {
log.Fatalf("error when getting pretty name: %s", err.Error())
}
fmt.Printf("Pretty Name: %s\n", pretty)
// Returns the platform of the client's distribution
// ex. ubuntu, centos, ol...
platform, err := distroyer.Platform()
if err != nil {
log.Fatalf("error when getting platform: %s", err.Error())
}
fmt.Printf("ID: %s\n", platform)
// Returns the version of the client's distribution
// ex. 22.04, 8.6, 6.3...
version, err := distroyer.Version()
if err != nil {
log.Fatalf("error when getting version: %s", err.Error())
}
fmt.Printf("Version: %s\n", version)
}
经测试的分布和操作系统
| 操作系统/Distro | 架构 | 版本 | 代号 | 像 | P.名称 |
|---|---|---|---|---|---|
| Ubuntu 18 / 20 / 22 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| 甲骨文服务器 8 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| Centos 7 / 8 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| Pardus 19 / 21 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| Windows 7 / 10 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
