Browse Source

Add static resoure handler + directory

develop
PrivateGER 3 years ago
parent
commit
63a40d3906
No known key found for this signature in database GPG Key ID: B9918E382ED08059
  1. 2
      .gitattributes
  2. 13
      PageHandlers/Static.go
  3. 4
      main.go

2
.gitattributes

@ -0,0 +1,2 @@
*.min.js -text -diff -delta
*.min.css -text -diff -delta

13
PageHandlers/Static.go

@ -0,0 +1,13 @@
package PageHandlers
import (
"embed"
"net/http"
)
//go:embed static
var staticEmbedFS embed.FS
func Static(writer http.ResponseWriter, request *http.Request) {
http.FileServer(http.FS(staticEmbedFS))
}

4
main.go

@ -64,6 +64,10 @@ func main() {
fmt.Println(time.Now().String(),request.URL) fmt.Println(time.Now().String(),request.URL)
PageHandlers.View(writer, request, &FL, path) PageHandlers.View(writer, request, &FL, path)
}) })
http.HandleFunc("/static", func(writer http.ResponseWriter, request *http.Request) {
fmt.Println(time.Now().String(),request.URL)
PageHandlers.Static(writer, request)
})
http.Handle("/videos/", http.StripPrefix("/videos/", http.FileServer(http.Dir(path)))) http.Handle("/videos/", http.StripPrefix("/videos/", http.FileServer(http.Dir(path))))
err := http.ListenAndServe(":" + strconv.Itoa(port), nil) err := http.ListenAndServe(":" + strconv.Itoa(port), nil)

Loading…
Cancel
Save