package Gorilla import ( "fmt" _ "fmt" "net/http" _ "net/http" _…
- User
package Gorilla
import ( "fmt" _ "fmt" "net/http" _ "net/http" _ "github.com/gorilla/mux" )
// Allouer un routeur Gorilla. router := mux.NewRouter() // MethodEEMI Routes filtrées par les méthodes. const MethodEEMI = "EEMI"
router.HandleFunc("/hello", helloHtml). Methods(http.MethodGet, MethodEEMI) router.HandleFunc("/", handlePost). Methods(http.MethodPost) // Route avec paramètres et validation. router.Path("/page/{page:[0-9]+}"). // Read with mux.Vars(r) HandlerFunc(handlePage). Methods(http.MethodGet) http.Handle("/", router) // Utiliser le routeur comme mux au lieu de DefaultMux err := http.ListenAndServe(":3000", router)
fix my code
- Assistant
To correct and improve your code snippet, you'll need to make a few changes for it to run properly within a Go program. Notably, your code lacks a proper structure and contains errors, such as trying to declare and use variables (like
router) outside of functions.