Questions tagged [servemux]

In go ServeMux is an HTTP request multiplexer. It matches the URL of each incoming request against a list of registered patterns and calls the handler for the pattern that most closely matches the URL.

In go ServeMux is an HTTP request multiplexer. It matches the URL of each incoming request against a list of registered patterns and calls the handler for the pattern that most closely matches the URL. more information: http://golang.org/pkg/net/http/#ServeMux

16 questions
49
votes
8 answers

Making golang Gorilla CORS handler work

I have fairly simple setup here as described in the code below. But I am not able to get the CORS to work. I keep getting this error: XMLHttpRequest cannot load http://localhost:3000/signup. Response to preflight request doesn't pass access…
Moon
  • 33,439
  • 20
  • 81
  • 132
45
votes
2 answers

What is an http request multiplexer?

I've been studying golang and I noticed a lot of people create servers by using the http.NewServeMux() function and I don't really understand what it does. I read this: In go ServeMux is an HTTP request multiplexer. It matches the URL of each…
hermancain
  • 1,452
  • 2
  • 18
  • 24
13
votes
1 answer

Testing HTTP routes in Golang

I am using Gorilla mux and the net/http package to create some routes as follows package routes //some imports //some stuff func AddQuestionRoutes(r *mux.Router) { s := r.PathPrefix("/questions").Subrouter() …
moesef
  • 4,641
  • 16
  • 51
  • 68
6
votes
2 answers

Go: How to combine two (or more) http.ServeMux?

Given that you have two instances of http.ServeMux, and you wish for them to be served at the same port number, like so: muxA, muxB http.ServeMux //initialise muxA //initialise muxB combinedMux := combineMux([muxA, muxB]) …
bguiz
  • 27,371
  • 47
  • 154
  • 243
3
votes
1 answer

Running two web server at the same time in one go programm

In a go program, I want to run two web servers at the same time, obviously they will be serving on two different ports (and ip addresses if necessary), the problem is with the call to http.handle, when I try to register handler for '/' for the…
Ali
  • 18,665
  • 21
  • 103
  • 138
1
vote
0 answers

Header Content-Type not set when ServeMux pattern has no trailing slash

I have the simplest HTTP server: package main import ( "net/http" ) func handle(w http.ResponseWriter, r *http.Request) { // Calling http://localhost:10000/test/ will not panic // Calling http://localhost:10000/test WILL panic if…
Andrew
  • 815
  • 8
  • 17
1
vote
2 answers

How to serve a file if URL doesn't match to any pattern in Go?

I'm building a Single Page Application using Angular 2 and Go, and in Angular I use routing. If I open the site at, say, http://example.com/, Go will serve me my index.html file, which is good because I wrote this: mux.Handle("/",…
Randex
  • 770
  • 7
  • 30
1
vote
1 answer

How to Use ServeMux with ServerConn?

Im creating a Networking API and want people to be able to route requests to specific endpoints using a ServeMux. Instead of using a Server instance, I need to use my own low level ServerConn. This is because I am receiving both incoming HTTP…
sourdesi
  • 360
  • 1
  • 4
  • 21
1
vote
2 answers

Gorilla Mux for sub path Routing

I have the following…
user4211028
1
vote
1 answer

Golang negroni and http.NewServeMux() issue

I am running a server with below code: // Assuming there is no import error mux := http.NewServeMux() mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { http.Error(w, "File not found", http.StatusNotFound) }) n :=…
Somesh
  • 1,235
  • 2
  • 13
  • 29
0
votes
1 answer

Declaring and assigning handlers to ServeMux in the loop does not work

I have the following piece of code, and it doesn't work as expected. Specifically, all the requests to any endpoints are being handled as requests to either /banana/auth or /banana/description endpoints. type Route struct { AuthRoute …
wintermute
  • 488
  • 1
  • 9
  • 22
0
votes
1 answer

Content written to response writer shows erratic behaviour

File: main.go import ( "github.com/gorilla/mux" ) func setupRouting(pBus *bus.Bus) *mux.Router { log.Debug("Setting up routing") r := mux.NewRouter() pInvoiceHandler := handlers.NewInvoiceHandler(pBus) …
deb
  • 631
  • 1
  • 5
  • 15
0
votes
1 answer

Go language cannot use r (type *mux.Router) as type *mux.Route in return argument

Hi i am initializing Router in other Go file and returning reference of it in Main file and then in Main file i am initializing serve. This piece of code is not compiling package router import ( "github.com/gorilla/mux" …
silentsudo
  • 6,730
  • 6
  • 39
  • 81
0
votes
1 answer

Gorilla Mux to handle curl request

I want to use Gorilla mux to handle api requests. Commands will be something like: curl http://0.0.0.0:8000/api/myapiname/v1?number=10&target=google.com&message=hello And I am serving with following…
user4211028
-2
votes
1 answer

Does MVC pattern implement common tasks of web framework?

The common tasks of web application framework(ex: Django or Laravel or .NET or beego): request / response abstraction session state user authentication & authorisation page templating URL mapping DB access security caching MVC design…
overexchange
  • 15,768
  • 30
  • 152
  • 347
1
2