go1.16 and embed

This commit is contained in:
ston1th 2021-02-18 22:36:49 +01:00
commit 8e7bcfc21b
37 changed files with 98 additions and 1134 deletions

View file

@ -5,6 +5,7 @@ package server
import (
"bytes"
"context"
"embed"
"errors"
"git.giftfish.de/ston1th/authdav"
"git.giftfish.de/ston1th/docstore/pkg/core"
@ -100,12 +101,16 @@ func (s *HTTPServer) Stop() error {
func (s *HTTPServer) register() http.Handler {
r := mux.NewRouter()
r.NotFoundHandler = &registerNotFoundHandler{s}
r.Handle("/static/{file}", http.StripPrefix("/", http.FileServer(http.FS(static))))
for _, v := range registerRoutes {
r.HandleFunc(v.Path, s.contextWrapper(v.Handler)).Methods(v.Methods...)
}
return r
}
//go:embed static/*
var static embed.FS
func (s *HTTPServer) buildRoutes() http.Handler {
r := mux.NewRouter()
r.NotFoundHandler = &notFoundHandler{s}
@ -115,6 +120,7 @@ func (s *HTTPServer) buildRoutes() http.Handler {
h := authdav.NewWebdavBasicAuth(core.WebDavPrefix, fs, nil, webdavLogger, s.DB, "DocStore WebDav")
r.PathPrefix(core.WebDavPrefix).Handler(h)
}
r.Handle("/static/{file}", http.StripPrefix("/", http.FileServer(http.FS(static))))
for _, v := range routes {
r.HandleFunc(v.Path, s.contextWrapper(v.Handler)).Methods(v.Methods...)
}