- Go 100%
| .gitignore | ||
| go.mod | ||
| main.go | ||
| README.md | ||
| sound.mp3 | ||
Project: Go Timer with Sound Notification
This project is a simple command-line countdown timer written in Go. When the timer reaches zero, it plays a sound notification using the external mpv media player and then exits after the sound completes.
Prerequisites
Before compiling and running, ensure you have the following installed on your system:
- Go: A working Go development environment.
- mpv: The media player
mpvmust be installed and accessible in your system's PATH.
To install mpv (Example for Debian/Ubuntu):
sudo apt update && sudo apt install mpv
To install mpv (Example for Arch Linux):
sudo pacman -S mpv
See the official mpv documentation for instructions specific to your operating system.
Sound File: A sound file named sound.mp3 must be placed in the same directory as the compiled executable for sound notification to work.
How to Run
Follow these steps in your terminal:
1. Compile the Project
Navigate to the gotimer directory and run:
go build -o gotimer main.go
2. Execute the Timer Run the compiled binary, passing the desired time duration using flags.
Usage Syntax:
./gotimer -m <minutes> -s <seconds>
Example: To set a timer for 2 minutes and 30 seconds:
./gotimer -m 2 -s 30
Flags
The program accepts the following command-line flags:
| Flag | Description | Type | Default |
|---|---|---|---|
-m |
Sets the duration in minutes. | Integer | 0 |
-s |
Sets the duration in seconds. | Integer | 0 |
Usage Note: The total time must be greater than zero. If no valid flags are provided, the program will exit with an error message.
Stopping the Program
- During Countdown: Press
Ctrl+Cto cancel the timer and stop any active sound. - After Countdown/Sound Playing: The program will automatically block and wait for the sound to finish playing. You will need to press
Ctrl+Cone final time to gracefully terminate the entire application.