Questions tagged [httprouter]

Matches the URL of incoming http request against a list of registered patterns and calls the matched handler for the pattern

21 questions
3
votes
1 answer

Context value is nil when getting it with unexported struct key in Go HTTP handlers

Any help here is appreciated! I'm sure that I'm missing something really basic. The problem I have is I am trying to get a value out of context in a demo web application, and I'm receiving the error: 2021/04/11 11:35:54 http: panic serving…
ngriffin
  • 327
  • 4
  • 11
2
votes
1 answer

Serve static content on root and rest on /api

I'm using httprouter for parsing some parameters from the path in api calls: router := httprouter.New() router.GET("/api/:param1/:param2", apiHandler) And wanted to add some files to the root (/) to serve. It's just index.html, script.js and…
microo8
  • 3,568
  • 5
  • 37
  • 67
2
votes
1 answer

httprouter pass in many middleware functions

I'm coming from node express, and I was able to pass in as many middleware as possible, for example: routes.use('/*', ensureAuth, logImportant, ... n); How can I do something similar when using r.GET("/", HomeIndex)? Am I forced to do something…
a person
  • 1,518
  • 3
  • 17
  • 26
1
vote
1 answer

httprouter panic: path must begin with '/' in path 'GET'

I am moving my handler from net/http / mux to httprouter and my tests are failing. I am doing a request to a server running in a separate go routine. httprouter is complaining that the path must start with /, not sure why. httprouter…
puppeteer701
  • 1,225
  • 3
  • 17
  • 33
1
vote
1 answer

go chi treating sub route path as URL param

i am creating a base router and adding few middlewares and health check route as below baseRouter := chi.NewRouter() baseRouter.Use(middleware.Logger) baseRouter.Use(core.CorsHandler) baseRouter.Get("/", func(w http.ResponseWriter, r *http.Request)…
vignesh
  • 498
  • 8
  • 18
1
vote
1 answer

How to nest routers in Go julienschmidt/httprouter?

I want to expose the following URLs from my service: GET /api/foo GET /api/bar I also want to structure it as a router nested inside another. The toplevel router will match all requests to /api and serve them with the nested router which will match…
Yawar
  • 11,272
  • 4
  • 48
  • 80
1
vote
1 answer

Using TLS/SSL Client Authentication for specific hosts

How can I use TLS/SSL Client Authentication for specific Hosts when using a reverse proxy like httprouter by julienschmidt? I could set a Client Certificate in a global matter with http.DefaultTransport. transport := &http.Transport{ …
hdev
  • 6,097
  • 1
  • 45
  • 62
1
vote
0 answers

can't match route with named parameters in finatra controller

I am using com.twitter.finatra.http.Controller to set up endpoints in Scala and I have an endpoint like this: get(s"${endpoint}/:id/lookup/?") {request: Request => println("here") val id = request.params("id") response.ok } It is my…
chibis
  • 658
  • 2
  • 12
  • 22
0
votes
1 answer

panic: http: multiple registrations for / (root path)

I am trying to start two http server on different ports, but unable to use the same pattern: handlerFunc1 := http.HandlerFunc(hello1) http.Handle("/", handlerFunc1) server1 := &http.Server{ Addr: "localhost:8081", Handler:…
Chris G.
  • 23,930
  • 48
  • 177
  • 302
0
votes
1 answer

How to handl these routes in go httprouter: /hello/:name and /hello/b/c?

httprouter does not allow this and panics when start. httprouter :panic: wildcard route ':name' conflicts with existing children in path '/hello/:name'. In my understanding, "/hello/:name" has two parts ,but /hello/b/c has three…
桃桃桃子
  • 159
  • 1
  • 2
  • 7
0
votes
1 answer

404 page not found when trying to use Gqlgen with julienschmidt/httprouter

Below is the code I run the issue is that I get 404 page not found instead of the graphql playground page Is it possible to work with httprouter with gqlgen or do I need to go back to chi or mux I also was not able to use middlewares because r does…
0
votes
1 answer

httprouter forward to another handler with parameters & url update

I'm thinking about the following scenario: Suppose I want have handler X in which I have made some calculations but now want to forward to another handler Y before returning the request. It would be something like func X(w http.ResponseWriter, r…
Jiulin Teng
  • 299
  • 3
  • 8
0
votes
1 answer

passing named parameters to index template while using httprouter golang package

I just learnt how to use the httprouter go package and read many documents about it but failed to use the :name style of passing paramenters toe templates when it comes to the index page template. ex. My router code: func getRouter()…
0
votes
1 answer

how to parse multiple parameters in url in GoLang?

I am new in Go. So please provide an example with your answer. I am using julienschmidt/httprouter. I am able to parse one parameter with this but how can I parse multiple parameters using this or any other library? The output I want to achieve is…
Mohit Yadav
  • 158
  • 3
  • 11
0
votes
2 answers

How to pass a httprouter.Handle to a Prometheus http.HandleFunc

Cannot pass Prometheus midware into httprouter endpoint definitions. I'm trying to add a Prometheus midware into our endpoint implementation. But our endpoint are using a third party mux package called httprouter. Then when I tried to add this…
wzf1943
  • 121
  • 1
  • 9
1
2