A simple timer written in Go
Find a file
Jesper Saastamoinen 1f873fd038 docs: add readme
2026-05-24 14:18:15 +02:00
.gitignore init repo 2026-05-24 14:11:07 +02:00
go.mod init repo 2026-05-24 14:11:07 +02:00
main.go init repo 2026-05-24 14:11:07 +02:00
README.md docs: add readme 2026-05-24 14:18:15 +02:00
sound.mp3 init repo 2026-05-24 14:11:07 +02:00

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:

  1. Go: A working Go development environment.
  2. mpv: The media player mpv must 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+C to 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+C one final time to gracefully terminate the entire application.