Skip to content

wildcard route ':slug' conflicts with existing children #49

Description

@DanikNik

I am using this code to implement a router, the openapi spec is given by my mentor so routes are not to be changed

type Route struct {
	Name    string
	Method  string
	Path    string
	Handler fasthttp.RequestHandler
}

type Routes []Route

func NewRouter() *fasthttprouter.Router {
	router := fasthttprouter.New()
	for _, route := range routes {
		var handler fasthttp.RequestHandler
		handler = route.Handler

		router.Handle(
			route.Method,
			route.Path,
			logger.Logger(
				middleware.ApplyMiddlewares(
					handler,
					middleware.ContentTypeMiddleware),
				route.Name),
		)
	}

	return router
}

var routes = Routes{
        Route{
		"ThreadCreate",
		strings.ToUpper("Post"),
		"/api/forum/:slug/create",
		controllers.ThreadCreate,
	},
	Route{
		"ForumGetOne",
		strings.ToUpper("Get"),
		"/api/forum/:slug/details",
		controllers.ForumGetOne,
	},

	Route{
		"ForumGetThreads",
		strings.ToUpper("Get"),
		"/api/forum/:slug/threads",
		controllers.ForumGetThreads,
	},

	Route{
		"ForumGetUsers",
		strings.ToUpper("Get"),
		"/api/forum/:slug/users",
		controllers.ForumGetUsers,
	}, ... <here more routes, these are for example>
}

So i have following issue:

panic: wildcard route ':slug' conflicts with existing children in path '/api/forum/:slug/create'

goroutine 1 [running]:
github.com/buaazp/fasthttprouter.(*node).insertChild(0xc0000b62d0, 0xc0000cbc01, 0x6d3d60, 0xc, 0x6d3d55, 0x17, 0xc00009cc00)
	/home/daniknik/go/src/github.com/buaazp/fasthttprouter/tree.go:236 +0x73b
github.com/buaazp/fasthttprouter.(*node).addRoute(0xc0000b62d0, 0x6d3d55, 0x17, 0xc00009cc00)
	/home/daniknik/go/src/github.com/buaazp/fasthttprouter/tree.go:193 +0x20c
github.com/buaazp/fasthttprouter.(*Router).Handle(0xc000084de0, 0xc00008c570, 0x4, 0x6d3d55, 0x17, 0xc00009cc00)
	/home/daniknik/go/src/github.com/buaazp/fasthttprouter/router.go:210 +0xbe
github.com/DanikNik/tech-park-db-hw/internal/pkg/router.NewRouter(0x4070e0)
	/home/daniknik/go/src/github.com/DanikNik/tech-park-db-hw/internal/pkg/router/router.go:27 +0x19f
main.main()
	/home/daniknik/go/src/github.com/DanikNik/tech-park-db-hw/cmd/main.go:10 +0x26

Am I using path variables incorrect or something else?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions