goutils
Collection of GoLang Utilities for Windows, Linux and macOS.
Packages
| Package |
Description |
clipboard |
Cross-platform clipboard read/write |
color |
Cross-platform console text coloring |
keyboard |
Cross-platform keyboard key press simulation |
prutils |
Console utilities (input validation, random, title, rect) |
Requirements
- Go 1.26 or later
- Windows: no extra tools needed
- macOS: Xcode Command Line Tools (for CGo in
keyboard package)
- Linux:
xsel, xclip, or wl-clipboard (for clipboard); kernel uinput module (for keyboard)
Installation
go get github.com/PrabhakarRai/goutils
Cross-Compilation & CGo
Important: The keyboard package uses CGo on Linux and macOS. This has implications for cross-compilation.
What is CGo?
CGo allows Go packages to call C code. The keyboard package on Linux uses linux/uinput.h and on macOS uses the Cocoa framework via Objective-C. This means:
- A C compiler (
gcc / clang) must be available when building.
- Cross-compiling from one OS to another does not work by default for the
keyboard package.
Cross-Compilation Instructions
Windows (pure Go — no CGo)
The keyboard package on Windows is pure Go. You can cross-compile to Windows from any OS:
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build ./...
Linux → Linux (same arch)
Standard build — CGo is enabled by default:
go build ./...
Linux → macOS / macOS → Linux
Cross-compiling with CGo requires a cross-toolchain. Options:
- Use Docker: Build inside a container matching the target OS.
- Disable the keyboard package: If you don't need
keyboard, you can exclude it:
go build $(go list ./... | grep -v keyboard)
- Use
CGO_ENABLED=0: Only works if your code does not import the keyboard package.
macOS builds (CGo required)
Ensure Xcode Command Line Tools are installed:
xcode-select --install
Then build normally:
go build ./...
The keyboard package on Linux requires the uinput kernel module and write access:
# Load the uinput module (once per boot)
sudo modprobe uinput
# Grant write access (adjust as needed for your distro)
sudo chmod +0666 /dev/uinput
go vet Note
The clipboard/clipboard_windows.go file contains intentional unsafe.Pointer conversions required for the Windows Clipboard API (GlobalLock). These trigger the unsafeptr go vet analyzer. To run vet without this false-positive:
go vet -unsafeptr=false ./...
All other vet checks pass cleanly.
License
See LICENSE.