-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from dadav/feat_ui
feat: Add basic web ui
- Loading branch information
Showing
32 changed files
with
1,928 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package middleware | ||
|
||
import ( | ||
"net/http" | ||
"sync" | ||
"time" | ||
) | ||
|
||
type Statistics struct { | ||
ActiveConnections int | ||
TotalConnections int | ||
TotalResponseTime time.Duration | ||
ConnectionsPerEndpoint map[string]int | ||
ResponseTimePerEndpoint map[string]time.Duration | ||
Mutex sync.Mutex | ||
} | ||
|
||
func NewStatistics() *Statistics { | ||
return &Statistics{ | ||
ActiveConnections: 0, | ||
TotalConnections: 0, | ||
TotalResponseTime: 0, | ||
ConnectionsPerEndpoint: make(map[string]int), | ||
ResponseTimePerEndpoint: make(map[string]time.Duration), | ||
} | ||
} | ||
|
||
func StatisticsMiddleware(stats *Statistics) func(next http.Handler) http.Handler { | ||
return func(next http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
start := time.Now() | ||
stats.Mutex.Lock() | ||
stats.ActiveConnections++ | ||
stats.TotalConnections++ | ||
stats.ConnectionsPerEndpoint[r.URL.Path]++ | ||
stats.Mutex.Unlock() | ||
|
||
defer func() { | ||
duration := time.Since(start) | ||
stats.Mutex.Lock() | ||
stats.ActiveConnections-- | ||
stats.TotalResponseTime += duration | ||
stats.ResponseTimePerEndpoint[r.URL.Path] += duration | ||
stats.Mutex.Unlock() | ||
}() | ||
|
||
next.ServeHTTP(w, r) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ui | ||
|
||
import ( | ||
"embed" | ||
"net/http" | ||
) | ||
|
||
//go:embed all:assets | ||
var assets embed.FS | ||
|
||
func HandleAssets() http.Handler { | ||
return http.FileServer(http.FS(assets)) | ||
} |
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.