File tree 1 file changed +6
-2
lines changed
1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ limitations under the License.
23
23
package main
24
24
25
25
import (
26
+ "embed"
26
27
"html/template"
27
28
"log"
28
29
"net/http"
@@ -35,10 +36,13 @@ func main() {
35
36
log .Fatal (http .ListenAndServe ("localhost:8080" , nil ))
36
37
}
37
38
39
+ //go:embed index.tmpl image.tmpl
40
+ var templateFS embed.FS
41
+
38
42
// indexTemplate is the main site template.
39
43
// The default template includes two template blocks ("sidebar" and "content")
40
44
// that may be replaced in templates derived from this one.
41
- var indexTemplate = template .Must (template .ParseFiles ( "index.tmpl" ))
45
+ var indexTemplate = template .Must (template .ParseFS ( templateFS , "index.tmpl" ))
42
46
43
47
// Index is a data structure used to populate an indexTemplate.
44
48
type Index struct {
@@ -70,7 +74,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
70
74
71
75
// imageTemplate is a clone of indexTemplate that provides
72
76
// alternate "sidebar" and "content" templates.
73
- var imageTemplate = template .Must (template .Must (indexTemplate .Clone ()).ParseFiles ( "image.tmpl" ))
77
+ var imageTemplate = template .Must (template .Must (indexTemplate .Clone ()).ParseFS ( templateFS , "image.tmpl" ))
74
78
75
79
// Image is a data structure used to populate an imageTemplate.
76
80
type Image struct {
You can’t perform that action at this time.
0 commit comments