To keep the blog post simple, I used the gpio command to interact with the GPIO pins on the Raspberry Pi.
That works well. But by deploying a little web server you can have an easier user interface to power on or reset your desktop computer remotely.
To interact with the GPIO pins from Go, you can use the package go-rpio.
With this package, you can open the interface to the GPIO pins by calling rpio.Open. Then, use the rpio.Pin type to control individual pins.
For example, to pulse the pin that controls the power switch relay, you could do this:
pin.Output() // Switch pin to output mode.
pin.Low() // Set the pin to low, activating the relay.
time.Sleep(250*time.Millisecond) // Wait for 250ms.
pin.High() // Set the pin back to high.
The web server then needs four endpoints:
Simulate a power button press
Simulate a long power button press
Simulate a reset button press
Serve the page with the three buttons
The page is essentially just 3 buttons wrapped in forms. Each of the three forms point to one of the three endpoints for triggering the relays through the GPIO pins.