Skip to content

Instantly share code, notes, and snippets.

@j178
Last active July 1, 2023 10:00
Show Gist options
  • Save j178/a669204b9bf943ad7cca5889daa9a574 to your computer and use it in GitHub Desktop.
Save j178/a669204b9bf943ad7cca5889daa9a574 to your computer and use it in GitHub Desktop.
Gin route confliction
package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/users/:name", func(c *gin.Context) {})
// can't use `:id` here, change to `:name` will fix the confliction
r.GET("/users/:id/repos", func(c *gin.Context) {})
_ = r.Run(":8080")
}
@j178
Copy link
Author

j178 commented Jul 1, 2023

echo:

package main

import "github.com/labstack/echo/v4"

func main() {
	e := echo.New()
	e.GET("/users/:name", func(c echo.Context) error { return nil })
	e.GET("/users/:id/repos", func(c echo.Context) error { return nil })
	e.Logger.Fatal(e.Start(":1323"))
}

chi:

package main

import (
	"net/http"
	"github.com/go-chi/chi/v5"
)

func main() {
	r := chi.NewRouter()
	r.Get("/users/{name}", func(w http.ResponseWriter, r *http.Request) {})
	r.Get("/users/{id}/repos", func(w http.ResponseWriter, r *http.Request) {})
	_ = http.ListenAndServe(":3000", r)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment