Browse Source

En cours de développement

master
losyme 5 months ago
parent
commit
36fa064bca
  1. 20
      router/subrouter.go

20
router/subrouter.go

@ -10,6 +10,7 @@ import (
"net/http"
"strings"
"forge.chapril.org/losyme/errors"
"forge.chapril.org/losyme/kong/context"
)
@ -96,6 +97,25 @@ func (sr *SubRouter) Group(path string, fn func(*Group)) {
})
}
func (sr *SubRouter) ServeFiles(path string, fs http.FileSystem) error {
const suffix = "/:filepath"
if len(path) < 10 || path[len(path)-10:] != suffix {
return errors.New("path must end with "+suffix, "path", path) //////////////////////////////////////////////////
}
fileServer := http.FileServer(fs)
sr.Get(path, func(c *context.Context) error {
c.Request.URL.Path = c.Param("filepath")
fileServer.ServeHTTP(c.Response, c.Request)
return nil
})
return nil
}
func (sr *SubRouter) match(path string, ctx *context.Context, ms *middlewares) *segment {
var ps string
seg := sr.routes

Loading…
Cancel
Save