Overview
gopsutil v4 introduces several breaking changes and new features designed to improve platform compatibility, type safety, and extensibility. This guide provides a comprehensive overview of what’s changed and how to update your code.What’s New in v4
Ex Structs for Platform-Specific Information
v4 introduces a new pattern for accessing platform-specific information throughEx structs. This allows you to access unique platform features while maintaining cross-platform compatibility in the core API.
Ex Structs Documentation
Learn how to use Ex structs to access platform-specific metrics
Improved Type Safety
Several functions now use more appropriate types:process.Uids()andprocess.Gids()now return[]uint32instead of[]int32- Better alignment with OS-level type definitions
Sensors Package
Temperature-related functionality has been moved from thehost package to a dedicated sensors package for better organization.
Breaking Changes
Import Path Update
Before (v3):Temperature Functions Moved
Before (v3):Process UID/GID Type Changes
Before (v3):New Features
Platform-Specific Ex Structs
v4 introducesEx structs to provide platform-specific information without breaking cross-platform compatibility. These are available in the mem and sensors packages.
Linux Example
Windows Example
Benefits of Ex Structs
- Platform-Specific Access: Get detailed metrics unique to each operating system
- Type Safety: Platform-specific fields are properly typed
- Backward Compatibility: Core API remains cross-platform while Ex provides extensions
- Clear Intent: Using Ex makes it explicit that code is platform-specific
Minimum Go Version
gopsutil v4 requires Go 1.18 or higher. This allows the use of generics and other modern Go features.Ensure your project is using Go 1.18+ before upgrading to v4
Migration Checklist
Additional Resources
v3 to v4 Migration
Step-by-step migration instructions
Platform-Specific Features
Learn about Ex structs and platform features
API Reference
Browse the complete v4 API documentation
GitHub Release Notes
View the official v4 release notes
Getting Help
If you encounter issues during migration:- Check the GitHub Issues for known problems
- Review the API Reference for detailed function signatures
- Ask questions in the GitHub Discussions