forked from mbk-lab/rui_orig
обработчик http
This commit is contained in:
parent
d7f0dd4358
commit
e41e61966f
|
@ -0,0 +1,36 @@
|
||||||
|
package rui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type httpHandler struct {
|
||||||
|
app *application
|
||||||
|
prefix string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *httpHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
|
switch req.Method {
|
||||||
|
case http.MethodGet:
|
||||||
|
path := `/` + strings.TrimPrefix(req.URL.Path, `/`)
|
||||||
|
req.URL.Path = `/` + strings.TrimPrefix(strings.TrimPrefix(path, h.prefix), `/`)
|
||||||
|
|
||||||
|
h.app.ServeHTTP(w, req)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHandler(urlPrefix string, createContentFunc func(Session) SessionContent, params AppParams) *httpHandler {
|
||||||
|
app := new(application)
|
||||||
|
app.params = params
|
||||||
|
app.sessions = map[int]Session{}
|
||||||
|
app.createContentFunc = createContentFunc
|
||||||
|
apps = append(apps, app)
|
||||||
|
|
||||||
|
h := &httpHandler{
|
||||||
|
app: app,
|
||||||
|
prefix: `/` + strings.Trim(urlPrefix, `/`),
|
||||||
|
}
|
||||||
|
|
||||||
|
return h
|
||||||
|
}
|
Loading…
Reference in New Issue