4
Watch
70
Star
9
Fork
1
Issue

HTTP request logger for Golang

ichtrojan
ichtrojan
pushedAt 8 months ago

ichtrojan/horus

Horus 𓂀

horus-hero

Introduction

Horus is a request logger and viewer for Go. It allows developers log and view http requests made to their web application.

horus-big-brother

Installation

Run the following command to install Horus on your project:

go get github.com/ichtrojan/horus

Initiate 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

Serve dashboard (optional)

horus-message-received

...
if err := listener.Serve(":8081", "{preferred_password}")); err != nil {
	log.Fatal(err)
}
...

NOTE
Visit /horus on the port configured to view the dashboard

Usage

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)
}))
...

You can explore the implementation in the example folder.

Built by

ucloud ads