In Go + FastCGI, does it make any sense to use multiple handlers? -


gopher newbie here. please kind :-)

i have setup have account on shared server runs apache + fastcgi on have no control. smoothly interfaces go, though. i'm more used using go net/http, figuring out how use net/http/fcgi seemed simple enough. here minimal test application:

package main  import (     "fmt"     "net/http"     "net/http/fcgi" )  func handler(w http.responsewriter, r *http.request) {     w.writeheader(http.statusok)     w.header().set("content-type", "text/plain; charset=utf-8")     fmt.fprintln(w, "this generated go running fastcgi app") }  func main() {     /*      *        *  done here should setup code etc. retained between calls      *        */     http.handlefunc("/", handler)     // concurrently handles requests     if err := fcgi.serve(nil, nil); err != nil {             panic(err)     } } 

now works beautifully , flawlessly: after compiling to, say, go-fcgi-test.fcgi , placing under appropriate directory, go code run url http://my.shared.web.server/go-fcgi-test.fcgi. sake of simplicity, i've left of actual processing out — works extracting form parameters, env variables (under go 1.9!) , forth, know basic setup must ok.

let's try more complicated example:

package main  import (     "fmt"     "net/http"     "net/http/fcgi" )  func handler1(w http.responsewriter, r *http.request) {     w.writeheader(http.statusok)     w.header().set("content-type", "text/plain; charset=utf-8")     fmt.fprintln(w, "this comes handler1") }  func handler2(w http.responsewriter, r *http.request) {     w.writeheader(http.statusok)     w.header().set("content-type", "text/plain; charset=utf-8")     fmt.fprintln(w, "this comes handler2") }  func main() {     http.handlefunc("/first", handler1)     http.handlefunc("/", handler2)     if err := fcgi.serve(nil, nil); err != nil {             panic(err)     } } 

now, in scenario, expect http://my.shared.web.server/go-fcgi-test.fcgi output this comes handler2, and, indeed, that's happens.

but why http://my.shared.web.server/go-fcgi-test.fcgi/first invoke handler2 well, i.e. handler1 ignored? note handler2 does /first bit of url — apache not stripping out — because can read r.url.path[1:] , confirm whole path sent go application.

all examples i've found on web using similar skeleton fastcgi show one handler. limitation of fastcgi package itself? limitation of fastcgi protocol (but why whole path correctly sent?)? done @ apache configuration imposes limitation (remember, cannot touch apache configuration)? or doing terribly wrong?

(for sake of completeness, should add yes, have tried out several variations of above, renaming go app, using subfolders, using several handlers , not one, etc. , forth)

my real world scenario small application supposed run either stand-alone web server using net/http or fastcgi application in case stand-alone model either not supported or forbidden (which case of providers of shared environments). since actual handling same either case, difference calling fcgi.serve() opposed http.listenandserve(). nice able use routing ability of net/http package different handlers under fastcgi well.

thanks in advance insight. , if answer 'yes, that's exactly how fastcgi implementation works under go — 1 handler only!' still useful — meaning need work around own code , things differently (basically, creating own router/dispatcher based on parameters passed through form interface — no big deal, it's doable!)


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -