mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-05-28 17:35:36 +02:00
Begin unit tests, relates to #35
This commit is contained in:
parent
da8f90d388
commit
be50af0a7a
11 changed files with 198 additions and 61 deletions
util
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue