diff options
| author | unwox <me@unwox.com> | 2024-06-12 20:15:15 +0600 |
|---|---|---|
| committer | unwox <me@unwox.com> | 2024-06-12 20:15:15 +0600 |
| commit | b173639424aa962185801cb70512d1ddd83dca3a (patch) | |
| tree | e0489234d12b64fcd5d81e0f69990f9b5b3ff0b5 | |
| parent | 9c4a7fd604eafb716e9162fded33a151bd2fb515 (diff) | |
fix http routing
| -rw-r--r-- | main.go | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -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)) } |
