Horus is a request logger and viewer for Go. It allows developers log and view http requests made to their web application.
Run the following command to install Horus on your project:
go get github.com/ichtrojan/horus
package main
import github.com/ichtrojan/horus
func main() {
listener, err := horus.Init("mysql", horus.Config{
DbName: "{preferred_database_name}",
DbHost: "{preferred_database_host}",
DbPssword: "{preferred_database_password}",
DbPort: "{preferred_database_port}",
DbUser: "{preferred_database_user}",
})
}
NOTE
Supported database adapters include mysql and postgres
...
if err := listener.Serve(":8081", "{preferred_password}")); err != nil {
log.Fatal(err)
}
...
NOTE
Visit/horus
on the port configured to view the dashboard
To enable horus to listen for requests, use the Watch
middleware provided by horus on the endpoints you will like monitor.
...
http.HandleFunc("/", listener.Watch(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
response := map[string]string{"message": "Horus is live 👁"}
_ = json.NewEncoder(w).Encode(response)
}))
...
Remember to either defer
or manually close the horos listener when you get a cancel signal on your server
defer listener.Close()
or
signal.Notify(sigChan, os.Kill)
signal.Notify(sigChan, os.Interrupt)
signal := <-sigChan
log.Printf("Received %s signal, gracefully shutting down", signal)
if err := listener.Close(); err != nil {
log.Fatalf("FATAL: Error while shutting down horus: %s", err)
}
You can explore the implementation in the example folder.