Is there anyway to get the route matching the request in fasthttp?

50 Views Asked by At

The server code is as follows

func requestHandler(ctx *fasthttp.RequestCtx) {
    id := ctx.UserValue("id").(string)
    name := ctx.UserValue("name").(string)

    response := fmt.Sprintf("Received ID: %s, Name: %s", id, name)
    ctx.SetBody([]byte(response))
}

func main() {
    r := router.New()

    r.GET("/rest/:id/:name", requestHandler)

    addr := ":9090"
    fmt.Printf("Starting server on %s\n", addr)
    if err := fasthttp.ListenAndServe(addr, r.Handler); err != nil {
        log.Fatalf("Error in ListenAndServe: %s", err)
    }
}

When I try to access http://localhost:8080/rest/1/peter, I hope to get the generic route "/rest/:id/:name".In go-restful I can get via SelectedRoutePath().

0

There are 0 best solutions below