🐧 DetectLinuxDistro
Detects the current Linux distribution information.
When to Use
Use this when you need to choose the appropriate package manager (apt/dnf/pacman/apk, etc.) based on the distribution to install PHP or Composer. Only effective on Linux. 🔍
Signature
go
func DetectLinuxDistro() (*DistroInfo, error)Parameters
| Parameter | Type | Description |
|---|---|---|
| None | — | Package-level function, takes no parameters |
Return Value
*DistroInfo: Distribution info containingID,Name,Version, andPackageManager. ✅error: Returns an error on non-Linux environments; when no clues are found,PackageManageris"unknown". ⚠️
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/installer"
)
func main() {
distro, err := installer.DetectLinuxDistro()
if err != nil {
log.Fatalf("failed to detect distro: %v", err)
}
fmt.Printf("%s %s (package manager: %s)\n", distro.Name, distro.Version, distro.PackageManager)
}Advanced
- Detection order:
/etc/os-release→lsb_releasecommand → distro-specific files (/etc/redhat-release, etc.) → fallback to available package managers. 🛠️ - Supports major distributions such as Ubuntu/Debian, Fedora/CentOS/RHEL, Arch, Alpine, openSUSE, and Gentoo. 📦
- The result is used by
InstallComposerViaPackageManagerandInstallPHP. 🔗