Junior — Middle
Millist marsruutimise raamatukogu või raamistikku kasutate oma projektides?
sobes.tech AI
Vastus AI-lt
In Go projects, the gorilla/mux library is often used for routing HTTP requests. It is simple to use, supports routes with parameters, HTTP methods, and middleware.
Example of using gorilla/mux:
import (
"net/http"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.HandleFunc("/users/{id}", func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id := vars["id"]
w.Write([]byte("User ID: " + id))
}).Methods("GET")
http.ListenAndServe(":8080", r)
}
Also popular are lighter routers, such as chi or the built-in http.ServeMux in the standard library, but gorilla/mux is often chosen for its flexibility and extensibility.