gorilla

config CORS in Gorilla Mux: 403 error on POST request

拈花ヽ惹草 提交于 2019-12-02 09:22:07
问题 I have an API, currently am trying to consume one of its endpoints. The endpoint is for POST requests, the endpoint is working as expected. The API is running in the cloud, I tested it with curl and it was perfect, then from my react app I was trying to consume it but I get 403 status code . Watching in the console of the browser I see that I get that error on a OPTIONS request, and the POST never get done. Here is a screenshot of the result displayed in the console: Then, I made a simple

How to escape forward slash in request to make url-routers count it as part of uri parameter?

不羁岁月 提交于 2019-12-02 04:29:41
I have following route mapping using gorilla/mux : router.Handle("/v1/data/{param}", handler) when I call curl http://localhost:8080/v1/data/hello%2Fworld I get 404 response code. The problem is that in my microservice I would like to interpret everything that goes after /v1/data/ as param . Code that's capturing params is following: uriP := mux.Vars(r) param := uriP["param"] Is it possible to achieve this using gorilla/mux or any other router? You should add regexp, bc default regexp is matching until / or ? symbols. router.Handle("/v1/data/{param:.*}", handler) For your question: Is it

Gorilla Mux router from inside handler only works once then gives 404 page not found

北城以北 提交于 2019-12-01 12:48:52
I'm using Gorilla mux as my router and I'm having a very strange behaviour. On the first request to the server, I get a valid response. But on subsequent requests, I receive a 404 page not found . There are no errors in the console. My code is pretty straightforward (it can be copy-pasted to test it right out): package main import ( "fmt" "github.com/gorilla/mux" "log" "net/http" ) func main() { router := mux.NewRouter() router.HandleFunc("/", RootHandler).Name("root") http.Handle("/", router) log.Println("Listening on port 1337...") if err := http.ListenAndServe(":1337", nil); err != nil {

Sending a Websocket message to a specific client in Go (using Gorilla)

孤人 提交于 2019-12-01 07:10:16
问题 I am very new to Go and have found myself working with sockets as my first project. This is a redundant question, but I have failed to understand how to send a websocket update to a specific client in Go (using Gorilla). The broad problem that I am trying to solve is - Building a typeahead using websockets and a search engine like ES/Lucene. I have maintained a bunch of indexes on my search engine and have a Go wrapper around it. When I started working on using websockets in Go, I have been

Making golang Gorilla CORS handler work

旧巷老猫 提交于 2019-11-30 12:36:57
问题 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 control check: No 'Access- Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. The response had HTTP status code 403. I am sure I am missing something simple here. Here is the

Sessions variables in golang not saved while using gorilla sessions

≯℡__Kan透↙ 提交于 2019-11-30 03:52:46
Session Variables are not maintained across request while using gorilla sessions web toolkit. When I start the server and type localhost:8100/ page is directed to login.html since session values do not exist.After I login I set the session variable in the store and the page is redirected to home.html. But when I open a new tab and type localhost:8100/ the page should be directed to home.html using already stored session variables, but the page is instead redirected to login.html. Following is the code. package main import ( "crypto/md5" "encoding/hex" "fmt" "github.com/gocql/gocql" "github.com

Sessions variables in golang not saved while using gorilla sessions

守給你的承諾、 提交于 2019-11-29 01:25:35
问题 Session Variables are not maintained across request while using gorilla sessions web toolkit. When I start the server and type localhost:8100/ page is directed to login.html since session values do not exist.After I login I set the session variable in the store and the page is redirected to home.html. But when I open a new tab and type localhost:8100/ the page should be directed to home.html using already stored session variables, but the page is instead redirected to login.html. Following is

Golang Gorilla mux with http.FileServer returning 404

左心房为你撑大大i 提交于 2019-11-28 20:18:10
The problem I'm seeing is that I'm trying to use the http.FileServer with the Gorilla mux Router.Handle function. This doesn't work (the image returns a 404).. myRouter := mux.NewRouter() myRouter.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir(HomeFolder + "images/")))) this works (the image is shown ok).. http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir(HomeFolder + "images/")))) Simple go web server program below, showing the problem... package main import ( "fmt" "net/http" "io" "log" "github.com/gorilla/mux" ) const ( HomeFolder = "

Gorilla mux custom middleware

前提是你 提交于 2019-11-28 17:03:32
I am using gorilla mux for manage routing. What I am missing is to integrate a middleware between every request. For example package main import ( "fmt" "github.com/gorilla/mux" "log" "net/http" "strconv" ) func HomeHandler(response http.ResponseWriter, request *http.Request) { fmt.Fprintf(response, "Hello home") } func main() { port := 3000 portstring := strconv.Itoa(port) r := mux.NewRouter() r.HandleFunc("/", HomeHandler) http.Handle("/", r) log.Print("Listening on port " + portstring + " ... ") err := http.ListenAndServe(":"+portstring, nil) if err != nil { log.Fatal("ListenAndServe error:

Golang Gorilla mux with http.FileServer returning 404

佐手、 提交于 2019-11-27 20:28:42
问题 The problem I'm seeing is that I'm trying to use the http.FileServer with the Gorilla mux Router.Handle function. This doesn't work (the image returns a 404).. myRouter := mux.NewRouter() myRouter.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir(HomeFolder + "images/")))) this works (the image is shown ok).. http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir(HomeFolder + "images/")))) Simple go web server program below, showing the problem...