From 9ca087edc9405019c319f8ec1ac7976e9231b278 Mon Sep 17 00:00:00 2001 From: surdeus Date: Thu, 7 Dec 2023 13:22:11 +0300 Subject: [PATCH] Added the static. --- cmd/test/main.go | 3 +++ handler.go | 3 +++ router.go | 6 +++--- static/file.html | 5 +++++ 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 static/file.html diff --git a/cmd/test/main.go b/cmd/test/main.go index 785f1e8..b8932b7 100644 --- a/cmd/test/main.go +++ b/cmd/test/main.go @@ -23,6 +23,9 @@ Def( c.W.Write([]byte("Привет, Мир!")) }), ), +).Def( + "web", + bond.Static("./static"), ) func main() { diff --git a/handler.go b/handler.go index 1c54872..e124cbf 100644 --- a/handler.go +++ b/handler.go @@ -23,3 +23,6 @@ func (fn ContextFunc) ServeHTTP(w ResponseWriter, r *Request) { }) } +func Static(pth string) Handler { + return http.FileServer(http.Dir(pth)) +} diff --git a/router.go b/router.go index 2d2c7f9..6fd1fed 100644 --- a/router.go +++ b/router.go @@ -3,7 +3,7 @@ package bond import ( "net/http" "strings" - "fmt" + //"fmt" "path" ) @@ -42,8 +42,8 @@ func (router *Router) ServeHTTP(w ResponseWriter, r *Request) { prefix = path.Clean("/" + name) } - fmt.Printf("Path: %q\n", r.URL.Path) - fmt.Printf("%q %q %q %q\n", pth, prefix, pths, name) + //fmt.Printf("Path: %q\n", r.URL.Path) + //fmt.Printf("%q %q %q %q\n", pth, prefix, pths, name) handler, ok := router.pathMap[name] if !ok { http.NotFound(w, r) diff --git a/static/file.html b/static/file.html new file mode 100644 index 0000000..b37767d --- /dev/null +++ b/static/file.html @@ -0,0 +1,5 @@ + + + + THE STATIC FILE +