schnutibox/assets/web/assets.go

38 lines
686 B
Go
Raw Normal View History

//nolint:gochecknoglobals
2021-05-03 14:51:53 +02:00
package web
2021-05-14 09:48:45 +02:00
import (
"embed"
"io/fs"
"net/http"
"github.com/rs/zerolog/log"
)
2021-05-03 14:51:53 +02:00
//go:embed files
2021-05-14 09:48:45 +02:00
var files embed.FS
// Files is the sub directed http.FileSystem for files.
2021-05-14 09:48:45 +02:00
var Files = sub(files, "files")
2021-05-03 14:51:53 +02:00
// Templates stores the templates.
2021-05-03 14:51:53 +02:00
//go:embed templates
var Templates embed.FS
2021-05-14 09:48:45 +02:00
//go:embed swagger-ui
var swaggerUI embed.FS
// SwaggerUI is the sub directed http.FileSystem for the swagger-ui.
2021-05-14 09:48:45 +02:00
var SwaggerUI = sub(swaggerUI, "swagger-ui")
func sub(f embed.FS, dir string) http.FileSystem {
fsys, err := fs.Sub(f, dir)
if err != nil {
log.Error().Err(err).Str("dir", dir).Msg("could not sub into dir")
return nil
}
return http.FS(fsys)
}