Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting nil value for path variables #69

Open
kamiiiel opened this issue Dec 3, 2019 · 2 comments
Open

Getting nil value for path variables #69

kamiiiel opened this issue Dec 3, 2019 · 2 comments

Comments

@kamiiiel
Copy link

kamiiiel commented Dec 3, 2019

I would expect to get the path variable but instead I get nil after few times calling the endpoint.
For example if you call this endpoint few times (maybe around 20 times) then you will get nil instead of "25". But for the first few requests it works fine.

package main

import (
"fmt"
"github.com/gramework/gramework"
)

func Hello(ctx *gramework.Context) {
ctx.Writef("Hello %s, id: %s!\n", ctx.UserValue("name"), ctx.UserValue("id"))
}

func main() {
app := gramework.New()
app.GET("/:id/:name", Hello)
app.ListenAndServe(":8080")
}

// Call the endpoint:
curl localhost:8080/25/Bob

I noticed that for the first few time, the path values are not cached so everything is fine but for the rest of the calls, these values are coming from the cache and then id becomes nil.

@kamiiiel kamiiiel changed the title nil value for path variables Getting nil value for path variables Dec 3, 2019
@kirillDanshin
Copy link
Member

@EliteGit please look into your gramework.Version

also, we have ctx.Writef, so you don't actually need to use fmt package :)

@kamiiiel
Copy link
Author

kamiiiel commented Dec 3, 2019

I'm using version 1.7.0
And it seems the issue is inside this file fasthttprouter_tree.go line 433

if n.hits > 32 {
n.router.cache.PutWild(reqPath, n, tsr, map[string]string{n.path[one:]: path[:end]}, method)
}

Here wrong path variables are saved in the cache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants