Is there any way to make two GET query parameters point to two different routes (handler functions) in Golang or GIN?

huangapple go评论71阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2022年12月30日 23:12:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/74963016.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定