1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-05-28 17:35:36 +02:00

Begin unit tests, relates to

This commit is contained in:
Philipp Heckel 2021-12-07 11:45:15 -05:00
parent da8f90d388
commit be50af0a7a
11 changed files with 198 additions and 61 deletions

View file

@ -8,11 +8,23 @@ import (
"time"
)
// CachingEmbedFS is a wrapper around embed.FS that allows setting a ModTime, so that the
// default static file server can send 304s back. It can be used like this:
//
// var (
// //go:embed docs
// docsStaticFs embed.FS
// docsStaticCached = &util.CachingEmbedFS{ModTime: time.Now(), FS: docsStaticFs}
// )
//
// http.FileServer(http.FS(docsStaticCached)).ServeHTTP(w, r)
//
type CachingEmbedFS struct {
ModTime time.Time
FS embed.FS
}
// Open opens a file in the embedded filesystem and returns a fs.File with the static ModTime
func (f CachingEmbedFS) Open(name string) (fs.File, error) {
file, err := f.FS.Open(name)
if err != nil {