From b173639424aa962185801cb70512d1ddd83dca3a Mon Sep 17 00:00:00 2001 From: unwox Date: Wed, 12 Jun 2024 20:15:15 +0600 Subject: fix http routing --- main.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index ccacca3..f12cf33 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( func main() { rch := make(chan *WorkerRequest, 4096) + mux := http.NewServeMux() for i := 0; i < 8; i++ { log.Printf("worker %d started\n", i) w := NewWorker(rch) @@ -17,7 +18,10 @@ func main() { } if i == 0 { for _, route := range w.ListRoutes() { - http.HandleFunc( + // we need to copy route otherwise it's going + // to change with every next iteration + route := route + mux.HandleFunc( route, func (wr http.ResponseWriter, r *http.Request) { resCh := w.Request(route, r) @@ -34,6 +38,6 @@ func main() { go w.Listen() defer w.Stop() } - fmt.Println("running") - log.Fatal(http.ListenAndServe("127.0.0.1:3002", nil)) + fmt.Println("luna is running...") + log.Fatal(http.ListenAndServe("127.0.0.1:3002", mux)) } -- cgit v1.2.3