mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 09:05:30 +00:00
Export xsl into seperate file via embedding
This commit is contained in:
25
functions/embedding.go
Normal file
25
functions/embedding.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package functions
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"io"
|
||||
"io/fs"
|
||||
)
|
||||
|
||||
// TODO: this needs to be cached, FS reads are expensive
|
||||
func EmbedSafe(fs fs.FS) func(string) template.HTML {
|
||||
return func(path string) template.HTML {
|
||||
f, err := fs.Open(path)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
data, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return template.HTML(data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user