这是我能想到的,虽然你需要移动中间件来回显
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
// Echo instance
e := echo.New()
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
r := mux.NewRouter()
r.HandleFunc("/mux/", Hello).Methods("GET", "PUT").Name("mux")
r.HandleFunc("/muxp/", HelloP).Methods("POST").Name("muxp")
gorillaRouteNames := map[string]string{
"mux": "/mux/",
"muxp": "/muxp/",
}
// Routes
e.GET("/", hello)
// ro := e.Any("/mux", ehandler)
for name, url := range gorillaRouteNames {
route := r.GetRoute(name)
methods, _ := route.GetMethods()
e.Match(methods, url, echo.WrapHandler(route.GetHandler()))
fmt.Println(route.GetName())
}
// Start server
e.Logger.Fatal(e.Start(":1323"))
}
// Handler
func hello(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
}
func Hello(w http.ResponseWriter, req *http.Request) {
fmt.Fprintln(w, "Hello world!")
}
func HelloP(w http.ResponseWriter, req *http.Request) {
fmt.Fprintln(w, "Hello world By Post!")
}