gorilla

Golang logging http responses (in addition to requests)

ε祈祈猫儿з 提交于 2019-12-05 09:25:37
I am using Go and the Gorilla web toolkit's mux and handler packages to build a complex application, part of which requires a http server. Gorilla's mux and handler packages work wonderfully and I am able to successfully get the http server up and running and it has been quite simple to log requests. However, I am unable to determine how I may log responses. Ideally, I would like a mechanism, similar to Gorilla's LoggingHandler, that "wraps" the logging mechanism easily. Is there a Golang package that does easily wraps / logs responses? Is there a way to use Go or Gorilla's capabilities in

golang go-endpoints Session using gorilla-toolkit

丶灬走出姿态 提交于 2019-12-04 16:32:17
I'm trying to implement Session handling and combine it with the go-endpoints package ! The package that i use to handle the session is Gorilla Sessions (github.com/gorilla/sessions), i would like some help.. I'm able to store a cookie to the client .. and when i call the endpoints is can see that the cookie is sent to the server. The problem while i try to get the Session values from the Session storage while the api is called, i cant get threw to the cookie .. it seams that the endpoints package strip the http.Request from extra content or something .. ? The place that i try to get the

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

爷,独闯天下 提交于 2019-12-04 14:45:27
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 second server, it panics and says there is already a handler associated with '/', I guess I need to create a mux in addition to the DefaultServeMux and I tried to do it using the gorillaMux but couldn't figure it out, Is there something fundamentally wrong with running two web servers in the same program/process. To make it more clear, one of the two

What is the advantage of using Gorilla sessions custom backend?

不打扰是莪最后的温柔 提交于 2019-12-04 02:44:38
I want to use Redis for session management. But I can't figure out what the advantage is of using Redis as a custom back-end for Gorilla sessions package over using it directly? link to the Gorilla session package: http://www.gorillatoolkit.org/pkg/sessions Gorilla sessions provides a means to wire up a storage system for session management provided you adhere to the interface provided. Currently, they give you two stores out of the box. One is a FilesystemStore that adheres to the interface that simply stores and retrieves session based data on the server's filesystem. The CookieStore as

How to add Authorization Header to Angular http request?

让人想犯罪 __ 提交于 2019-12-03 17:57:32
问题 This is my first post. I've just started learning Go and Angular and I'm attempting to connect the angular app to a go api. I've written both and am stuck identifying the root of the problem. I thought it was a CORS problem, but it works fine if I don't include the headers line of code in my Angular http request. At this point I'm just trying to add the header. The authorization code isn't implemented yet. Both apps are running locally with the Go app on port 5000 and Angular on 4200 Angular

Testing HTTP routes in Golang

末鹿安然 提交于 2019-12-03 12:21:21
问题 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() s.HandleFunc("/{question_id}/{question_type}", getQuestion).Methods("GET") s.HandleFunc("/", postQuestion).Methods("POST") s.HandleFunc("/", putQuestion).Methods("PUT") s.HandleFunc("/{question_id}", deleteQuestion).Methods("DELETE") } I am trying to write a test to test these routes. For

Can't use go tool pprof with an existing server

[亡魂溺海] 提交于 2019-12-03 10:56:05
I have an existing http server which I would like to profile. I have included _ "net/http/pprof" to my imports, and I already have http server running: router := createRouter() server := &http.Server { Addr: ":8080", Handler: router, ReadTimeout: 15*time.Second, WriteTimeout: 15*time.Second, // MaxHeaderBytes: 4096, } log.Fatal(server.ListenAndServe()) When I'm trying to access http://localhost:8080/debug/pprof/ I get 404 page not found . That's what I get when using go tool pprof on a local machine: userver@userver:~/Desktop/gotest$ go tool pprof http://192.168.0.27:8080/ Use of uninitialized

Gorilla WebSocket disconnects after a minute

不问归期 提交于 2019-12-03 02:55:28
I'm using Go (Golang) 1.4.2 with Gorilla WebSockets behind an nginx 1.4.6 reverse proxy. My WebSockets are disconnecting after about a minute of having the page open. Same behavior occurs on Chrome and Firefox. At first, I had problems connecting the server and client with WebSockets. Then, I read that I needed to tweak my nginx configuration. This is what I have. server { listen 80; server_name example.com; proxy_pass_header Server; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forward-Proto $scheme; proxy_http_version 1.1; proxy_set

How do I pass arguments to my handler

我的未来我决定 提交于 2019-12-02 19:06:25
I am trying to pass my database object along to my handlers, instead of having a global object. But I don't know if this is possible, I'm using Gorilla Mux package, and I can see that it takes a closure as a second param. // https://github.com/gorilla/mux/blob/master/mux.go#L174 // HandleFunc registers a new route with a matcher for the URL path. // See Route.Path() and Route.HandlerFunc(). func (r *Router) HandleFunc(path string, f func(http.ResponseWriter, *http.Request)) *Route { return r.NewRoute().Path(path).HandlerFunc(f) } Which then defines the params i can use, ideally i would like to

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

﹥>﹥吖頭↗ 提交于 2019-12-02 10:37:27
问题 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? 回答1: You should add regexp, bc default regexp is