Generated handler functions have this form:
api.StaticSayHelloHandler = static.SayHelloHandlerFunc(func(params static.SayHelloParams) middleware.Responder {
return middleware.NotImplemented("operation static.SayHello has not yet been implemented")
})
How you would implement websockets HTTP upgrade function with go-swagger? Is there any way to access ResponseWriter and Request? An upgrade looks like this:
func serveWs(hub *Hub, w http.ResponseWriter, r *http.Request) {
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Println(err)
return
}
}
you can implement a responder function which is: func(http.ResponseWriter, runtime.Producer)
https://github.com/go-openapi/runtime/blob/master/middleware/context.go#L59
The params struct has access to the http.Request and with the responder function you have access to the response writer
api.StaticSayHelloHandler = static.SayHelloHandlerFunc(func(params static.SayHelloParams) middleware.Responder {
return middleware.ResponderFunc(func(rw http.ResponseWriter, _ runtime.Producer){
conn, err := upgrader.Upgrade(rw, params.HTTPRequest, nil)
if err != nil {
log.Println(err)
return
}
})
})
Works like a charm, thank you! ;)
@CuBiC3D, @casualjim, it looks like this is using gorilla websockets right? How would you recommend describing the websocket in yaml?