Questions tagged [mux]

Package gorilla/mux implements a request router and dispatcher for matching incoming requests to their respective handler.

331 questions
2
votes
0 answers

Redirecting or using a handler inside a handler

Hi I am using go and gorilla-mux. I have a route handler that processes the request and I want to use another handler based on what happened with the request processing. E.g. my main route at /file/{file} processes the content type and then goes to…
Alex
  • 95
  • 1
  • 4
2
votes
0 answers

Gorila mux's subroute routing behaviour

I want to build a simple api server, and wanted to use gorila mux subrouter and faced the following issues //Sample function func Func1(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello")) w.WriteHeader(200) } func Func2(w…
Sab
  • 485
  • 5
  • 17
2
votes
2 answers

How to unit testing with Gorm, mux, postgresql

I'm new in Go and unit test. I build a samll side projecy called "urlshortener" using Go with Gorm, mux and postgresql. There is a qeustion annoying me after search many articles. To make the question clean, I delete some irrelevant code like…
2
votes
0 answers

Bind mutiple routers - Golang Gorilla Mux

I have the following grouped routes, that use different middlewares func userRoutes(handlers *Handler) *mux.Router { router := mux.NewRouter() // Routes here router.HandleFunc("/accounts", handlers.ListAccounts).Name("list-account") …
DeeStarks
  • 320
  • 5
  • 16
2
votes
0 answers

How to add query parameters using Gorilla Mux?

This is how i build my routes at the time so far using Gorilla Mux. Now i need to add query params to my routes. This is how im doing at this moment: type Route struct { Name string Method string Pattern string …
2
votes
0 answers

Test API endpoints with AWS SDK integration

I'm trying to test my API endpoint that list files from an AWS S3 Bucket: func listFiles(w http.ResponseWriter, _ *http.Request) { client := GetAWSClient() bucket := aws.String(BUCKETNAME) input := &s3.ListObjectsV2Input{ …
Loren
  • 333
  • 5
  • 20
2
votes
1 answer

Rate limiter with gorilla mux

I am trying to implement http request limiter to allow 10 request per second per user by their usernames. At the max 10 request can be hit to the server including requests which are under processing. Below is what I have implemented with reference…
ganesh.go
  • 39
  • 8
2
votes
1 answer

How to get client ip address using gorilla/mux - GoLang

I am implementing an API application in golang using gorilla/mux which is a powerfull library, tends to help to build web APIs, However i need to keep ip address for each client for that how can i get ip address for each client who visits…
user13128707
2
votes
1 answer

Gzip header forces file download

I am trying to gzip all responses. In main.go mux := mux.NewRouter() mux.Use(middlewareHeaders) mux.Use(gzipHandler) Then I have the middlewares: func gzipHandler(next http.Handler) http.Handler { return http.HandlerFunc(func(w…
pigfox
  • 1,301
  • 3
  • 28
  • 52
2
votes
1 answer

Mount double http routers in Go

I'm trying to mount 2 http routeurs such as: http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) }) r := mux.NewRouter() r.HandleFunc("/foo",…
Arkon
  • 2,648
  • 6
  • 26
  • 46
2
votes
1 answer

Fileserver directory for dynamic route

My scenario Compiled angular projects are saved like . ├── branch1 │   ├── commitC │   │   ├── app1 │   │   │   ├── index.html │   │   │   └── stylesheet.css │   └── commitD │   ├── app1 │   │   ├── index.html │   │   └──…
2
votes
0 answers

I am trying to test an REST Api client in Golang using mux and httptest

Here I am trying to write a test for a REST client, by writing the apiOutput into the http.ResponseWriter but I always receive {nil nil} as apiResponse. Can someone help me in pointing out the error ? func Test_Do(t *testing.T) { mux :=…
James Sapam
  • 16,036
  • 12
  • 50
  • 73
2
votes
1 answer

How to use Gorilla Mux for URL matching?

I have a validator function to check if a given path matches a path in array of paths. Current Logic: var allowed := String{"/users", "/teams"} func Validator(path String) bool { for _, p := range allowed { if path == p { return…
Sahith Vibudhi
  • 4,935
  • 2
  • 32
  • 34
2
votes
1 answer

Gorilla Mux Regex for url is not matching the full url

What regex should I use to match the following url as the full_path? https://edition.cnn.com/search\?q\=test\&size\=10\&category\=us,politics,world,opinion,health The (?:www.|http\:\/\/|https\:\/\/).*} does not work it matches only www. and up…
Olive.b
  • 93
  • 4
2
votes
1 answer

gorilla/mux requests not matching URL pattern

I'm visiting some old code for a simple webserver I wrote some time ago, and my request patterns are no longer working. I have a function that initializes my routes as follows: func (a *App) InitializeRoutes() { …
K Pekosh
  • 633
  • 1
  • 6
  • 15