The "too many open files" error occurs because your Go program has exceeded the operating system's limit on open file descriptors. Increase the limit for your shell session before running the program. On macOS and Linux, use the ulimit command to raise the soft limit:
ulimit -n 65536
go run main.go
If you need a permanent fix, add fs.file-max to your system configuration or adjust the limit in your init system (e.g., /etc/security/limits.conf on Linux).