Skip to content

Commit b1972fb

Browse files
committed
Add way to test looping from webserver to itsef
1 parent 361ea89 commit b1972fb

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gor.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ var (
2222
memprofile = flag.String("memprofile", "", "write memory profile to this file")
2323
)
2424

25-
func loggingMiddleware(next http.Handler) http.Handler {
25+
func loggingMiddleware(addr string, next http.Handler) http.Handler {
2626
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
27+
if r.URL.Path == "/loop" {
28+
_, err := http.Get("http://" + addr)
29+
log.Println(err)
30+
}
31+
2732
rb, _ := httputil.DumpRequest(r, false)
2833
log.Println(string(rb))
2934
next.ServeHTTP(w, r)
@@ -45,7 +50,7 @@ func main() {
4550

4651
Debug(0, "Started example file server for current directory on address ", args[1])
4752

48-
log.Fatal(http.ListenAndServe(args[1], loggingMiddleware(http.FileServer(http.Dir(dir)))))
53+
log.Fatal(http.ListenAndServe(args[1], loggingMiddleware(args[1], http.FileServer(http.Dir(dir)))))
4954
} else {
5055
flag.Parse()
5156
checkSettings()

0 commit comments

Comments
 (0)