go1.16 and embed

This commit is contained in:
ston1th 2021-02-18 22:36:16 +01:00
commit 82fd34b288
42 changed files with 95 additions and 1236 deletions

View file

@ -5,6 +5,7 @@ package server
import (
"bytes"
"context"
"embed"
"errors"
"git.giftfish.de/ston1th/godrop/v2"
"git.giftfish.de/ston1th/gowiki/pkg/core"
@ -78,17 +79,19 @@ func (s *HTTPServer) Stop() error {
return s.srv.Shutdown(ctx)
}
//go:embed static/*
var static embed.FS
func (s *HTTPServer) buildRoutes() http.Handler {
m := mux.NewRouter()
m.NotFoundHandler = &notFoundHandler{s}
for _, v := range static {
m.HandleFunc(v.Path, s.contextWrapper(v.Handler)).Methods(v.Methods...)
}
m.Handle("/static/{file}", http.StripPrefix("/", http.FileServer(http.FS(static))))
for _, v := range routes {
m.HandleFunc(v.Path, s.contextWrapper(v.Handler)).Methods(v.Methods...)
}
return m
}
func (s *HTTPServer) contextWrapper(h ctxHandler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
h(newContext(w, r, s))