Skip to content

Commit

Permalink
Merge pull request #13 from ichtrojan/prepare-release
Browse files Browse the repository at this point in the history
v1.0.0
  • Loading branch information
ichtrojan authored Mar 24, 2021
2 parents fa5681b + 24980ca commit d1da14f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 6 deletions.
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Horus 𓂀

<img width="1461" alt="horus-hero" src="https://user-images.githubusercontent.com/5338836/112303700-e2a23480-8c9c-11eb-9e47-9b0634e5b1e5.png">

## Introduction

Horus is a request logger and viewer for [Go](https://golang.org). It allows developers log and view http requests made to their web application.

<img width="1461" alt="horus-big-brother" src="https://user-images.githubusercontent.com/5338836/112304004-44629e80-8c9d-11eb-930b-bdf32448673c.png">

## Installation

Run the following command to install Horus on your project:

```bash
go get github.com/ichtrojan/horus
```

### Initiate horus

```go
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**<br/>
> Supported database adapters include **mysql** and **postgres**
### Serve dashboard (optional)

<img width="1461" alt="horus-message-received" src="https://user-images.githubusercontent.com/5338836/112304136-69571180-8c9d-11eb-80db-167c6e8c4d3c.png">

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

### Usage
To enable horus to listen for requests, use the `Watch` middleware provided by horus on the endpoints you will like monitor.

```go
...
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](https://github.com/ichtrojan/horus/tree/main/example).

## Built by

* Toni Akinmolayan - [twitter](https://twitter.com/toniastro_) [GitHub](https://github.com/toniastro)
* Michael Trojan Okoh - [twitter](https://twitter.com/ichtrojan) [GitHub](https://github.com/ichtrojan)



11 changes: 5 additions & 6 deletions horus.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
)

var METHODS = map[string]string{
"get": "GET",
"post": "POST",
"get": "GET",
"post": "POST",
"delete": "DELETE",
"option": "OPTION",
"put": "PUT",
"put": "PUT",
}

type InternalConfig struct {
Expand Down Expand Up @@ -279,7 +279,7 @@ func connect(config InternalConfig) (*gorm.DB, error) {
func (config InternalConfig) showLogs(w http.ResponseWriter, r *http.Request) {
lastID := r.URL.Query().Get("lastID")
method := r.URL.Query().Get("method")
method = METHODS[method]
method = METHODS[method]

var req []models.Request

Expand All @@ -295,9 +295,8 @@ func (config InternalConfig) showLogs(w http.ResponseWriter, r *http.Request) {
if err != nil {
_ = fmt.Errorf("%v", err)
}
fmt.Println(method)

if method == ""{
if method == "" {
method = "%"
}

Expand Down

0 comments on commit d1da14f

Please sign in to comment.