2021-05-31 08:48:28 +02:00
|
|
|
//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
|
|
|
|
|
2021-05-31 08:48:28 +02:00
|
|
|
// 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
|
|
|
|
2021-05-31 08:48:28 +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
|
|
|
|
|
2021-05-31 08:48:28 +02:00
|
|
|
// 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)
|
|
|
|
}
|