runtime - Runtime Information
Overview
The runtime module provides system information, runtime diagnostics, and path utilities for Go applications.
Functions
CachePanic()
Cache panic and prevent stack overflow.
Behavior:
- Catches panic and prevents stack overflow
- Writes panic information to stderr
- Dumps stack trace
CachePanicWithHandle()
Cache panic with custom handler.
Parameters:
handle- Custom panic handler function
Example:
PrintStack()
Print current stack trace.
Example:
ExecDir()
Get executable directory.
Returns:
- Directory containing the executable
- Empty string if error occurs
Example:
ExecFile()
Get executable file path.
Returns:
- Full path to the executable
- Empty string if error occurs
Example:
Pwd()
Get current working directory.
Returns:
- Current working directory
- Empty string if error occurs
Example:
UserHomeDir()
Get user home directory.
Returns:
- User home directory
- Empty string if error occurs
Example:
UserConfigDir()
Get user config directory.
Returns:
- Platform-specific user config directory
- Empty string if error occurs
Example:
UserCacheDir()
Get user cache directory.
Returns:
- Platform-specific user cache directory
- Empty string if error occurs
Example:
LazyConfigDir()
Get lazygophers config directory.
Returns:
- User config directory with lazygophers organization
Example:
LazyCacheDir()
Get lazygophers cache directory.
Returns:
- User cache directory with lazygophers organization
Example:
Usage Patterns
Application Initialization
Panic Recovery
Debug Information
Custom Panic Handler
Platform-Specific Paths
Linux/Unix
macOS
Windows
Best Practices
Panic Handling
Path Resolution
Debug Information
Related Documentation
- osx - OS operations
- app - Application framework
- API Documentation
- Module Overview