This is how i build my routes at the time so far using Gorilla Mux. Now i need to add query params to my routes. This is how im doing at this moment:
type Route struct {
Name string
Method string
Pattern string
HandleFunc http.HandlerFunc
}
func NewRouter(sqlDb *data.Data, redisClient *redis.Client) Router {
return &router{
sqlDb: sqlDb,
redisClient: redisClient,
}
}
func (r *router) MapRoutes() {
r.buildUserRoutes()
}
func routesCreation(routes Routes, r *router) {
for _, route := range routes {
r.Router.Methods(route.Method).
Path(route.Pattern).
Name(route.Name).
Handler(route.HandleFunc)
}
}
var userRoutes = Routes{
Route{"ping", "GET", "/ping", handler.Ping},
}
This is what i tried, adding a slice of string as a field on Route struct but it did not worked:
type Route struct {
Name string
Method string
Pattern string
HandleFunc http.HandlerFunc
Queries []string
}
func NewRouter(sqlDb *data.Data, redisClient *redis.Client) Router {
return &router{
sqlDb: sqlDb,
redisClient: redisClient,
}
}
func (r *router) MapRoutes() {
r.buildUserRoutes()
}
func (r *router) buildUserRoutes() {
p := []string{"a", "b"}
var userRoutes = Routes{
Route{"ping", "GET", "/ping", handler.Ping, p},
}
func routesCreation(routes Routes, r *router) {
for _, route := range routes {
r.Router.Methods(route.Method).
Path(route.Pattern).
Name(route.Name).
Handler(route.HandleFunc).
Queries(route.Queries)
}
}
Is it possible to add query params with this config for routes creations?
Thanks!