system-shutdown
provides a cross-platform way to shut down, reboot, sleep, or hibernate operations.
Supported platforms: Linux, Windows, and macOS.
Based on the work from the Rust crate system_shutdown
.
Add this to your go.mod
:
require (
github.com/plackemacher/system-shutdown
)
and then:
package main
import (
"fmt"
"github.com/plackemacher/system-shutdown"
"os"
)
func main() {
err := system_shutdown.Shutdown()
if err != nil {
println("Shutting down, bye!")
} else {
fmt.Fprintf(os.Stderr, "Failed to shut down: %v", err)
}
}
In most of the systems it does not require the user to be root or admin.
Pull Requests are welcome! =)
system-shutdown
is licensed under either of the following, at your option: