英文:
Is there any way to make two GET query parameters point to two different routes (handler functions) in Golang or GIN?
问题
我正在尝试做以下操作:
> /car?color= -> 第一个路由(端点)和第一个处理函数
>
> /car?brand= -> 第二个路由(端点)和第二个处理函数
>
> /car?type= -> 第三个路由(端点)和第三个处理函数
>
> ...
我在GIN中尝试了以下代码:
server.GET("/car?color=", carColorHandlerFunction)
server.GET("/car?brand=", carBrandHandlerFunction)
server.GET("/car?type=", carTypeHandlerFunction)
也尝试了以下代码:
server.GET("/car?color=:carColor", carColorHandlerFunction)
server.GET("/car?brand=:carBrand", carBrandHandlerFunction)
server.GET("/car?type=:carType", carTypeHandlerFunction)
不幸的是,它不起作用。它无法识别这些路由。
有没有办法使其工作,并且如何在GIN或者"basic" GO中实现?
英文:
I am trying to do the following:
> /car?color= -> first route (endpoint) and first handler function
>
> /car?brand= -> second route (endpoint) and second handler function
>
> /car?type= -> third route (endpoint) and third handler function
>
> ...
I tried the following in GIN:
server.GET("/car?color=", carColorHandlerFunction)
server.GET("/car?brand=", carBrandHandlerFunction)
server.GET("/car?type=", carTypeHandlerFunction)
Also tried:
server.GET("/car?color=:carColor", carColorHandlerFunction)
server.GET("/car?brand=:carBrand", carBrandHandlerFunction)
server.GET("/car?type=:carType", carTypeHandlerFunction)
Unfortunately, it does not work. It does not recognize these routes.
Is there a way to make it work and how to make it with a GIN or with "basic" GO?
答案1
得分: 0
有没有办法让它工作,并且如何使用GIN或者"basic" GO来实现?
没有。
或者使用"basic" GO呢?
也没有。
英文:
> Is there a way to make it work and how to make it with a GIN
No.
> or with "basic" GO?
No.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论