package main import ( "biukop/sfm/loan" "net/http" "net/http/httputil" ) const apiV1Prefix = "/api/v1/" type apiV1HandlerMap struct { Method string Path string //regex Handler func(http.ResponseWriter, *http.Request, *loan.Session) } var apiV1Handler = []apiV1HandlerMap{ {"POST", "login", apiV1Login}, {"GET", "login", apiV1DumpRequest}, } //apiV1Main version 1 main entry for all REST API // func apiV1Main(w http.ResponseWriter, r *http.Request) { logRequestDebug(httputil.DumpRequest(r, true)) w.Header().Set("Content-Type", "application/json;charset=UTF-8") path := r.URL.Path[len(apiV1Prefix):] //strip API prefix session := loan.Session{} session.Retrieve(r) //TODO: check remote_addr changes in DB, to prevent possible Hack for _, node := range apiV1Handler { if r.Method == node.Method && path == node.Path { node.Handler(w, r, &session) return } } //Catch for all apiV1DumpRequest(w, r, &session) } func apiV1ErrorCheck(e error) { if nil != e { panic(e.Error()) } }