#Gin - Parameter in path simply doesn't work

43 messages · Page 1 of 1 (latest)

ripe jay
#

When i create a path like this, it works;

    api.GET("/kspm/:id", myMiddleware, myRoute)

When i create a path like this;

    api.GET("/kspm/:scanid", myMiddleware, myRoute)

It doesn't work. For some reason I can only use :id as parameter.

And by doesn't work what i mean is, when run my app, gin lists all the routes to you right. But it gets stuck in that specific route and the rest of the routes doesn't work.

cloud plover
#

those paths are identical

ripe jay
cloud plover
#

do you have both defined or just one?

ripe jay
#

Just one

#

Afaik it would give an error if i were to define both anyway

cloud plover
#

can you provide the full code? something that i can test locally?

ripe jay
#

I don't think i can do that, it's company's code. But i can provide as much info as you need

cloud plover
#

try making a minimal example that captures the gist of the issue. i dont really have much to work with here

ripe jay
#

It gets stuck in there

#

Doesn't list the remaining routes

#

and the remaining routes don't work also

#

I don't get any errors or anything

cloud plover
#

without some code it's gonna be really difficult for me to help here, unfortunately

ripe jay
#

What were you going to look at if i were to create a minimal example?

cloud plover
#

the issue with path registration bugs is that its a really finicky thing. it's hard to debug without just auditing code. usually you spend enough time staring at the code and you find something that doesn't look right. i would try commenting out all the other routes and goign from there. asking a coworker to take a look, etc.

ripe jay
#

Is there any other platform i can reproduce?

cloud plover
#

if its something you can share you can share the link and i can try taking a look and running it locally

#

otherwise, im not sure, you'd like a full on vm or something since you'd need to open ports and run http requests without doing something convoluted using $[net/http/httptest]

brazen nightBOT
ripe jay
# cloud plover if its something you can share you can share the link and i can try taking a loo...

Let me post the related code snippets in my code then, maybe you can spot something;

import(
    "github.com/gin-gonic/gin"
    "github.com/gin-gonic/gin/binding"
)
func main(){
      err = StartServer()
    if err != nil {
        os.Exit(1)
    }  
}
func StartServer() error {
    router := SetupRouter()
    err := router.Run(":3000")
    return err
}
func SetupRouter() *gin.Engine {
  router := gin.New()
  router.SetTrustedProxies(nil)

  api := router.Group("/api/app")
    {
api.GET("/kspm/hello", middleware, route)
api.GET("/kspm/:id", middleware, route)
api.GET("/kspm/:clustertoken/:scanid/", middleware, route)
api.GET("/kspm/abc/abc/hi-i-dont-work", middleware, route)
        }
  return router
}
#

anything looks funky?

#

My gin version is
github.com/gin-gonic/gin v1.9.1

cloud plover
#

because its registered after :id

#

that has to be registered before it

ripe jay
#

i edited it

cloud plover
#

it stiill doesn't look right

ripe jay
#

yeaaah

#

the thing is

#

these give errors afaik

#

in my issue i don't get an error at all

cloud plover
#

i stand corrected. gin allows it. but the go stdlib router does not

ripe jay
#

and if it were, at least it would give an error so i could fix that

cloud plover
#

ok, well, im only working with what i got

ripe jay
#

Yeah. I literally copy pasted all the related code as well. I don't know what's wrong. maybe its the versions.

Anyways im just gonna edit my route to be something else.

Thank you for trying to help.

cloud plover
#

good luck

ripe jay
#

yeah with this backend code i will need that