use go:embed to include forms.html into cpmpiled binary
This commit is contained in:
parent
f9295b74ee
commit
bd3b2817f2
1 changed files with 4 additions and 1 deletions
5
main.go
5
main.go
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
|
@ -97,6 +98,8 @@ type Source struct {
|
||||||
var (
|
var (
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
chars []Character
|
chars []Character
|
||||||
|
//go:embed forms.html
|
||||||
|
page embed.FS
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -112,7 +115,7 @@ func main() {
|
||||||
// formHandler zeigt das Formular an
|
// formHandler zeigt das Formular an
|
||||||
func formHandler(filename string) http.HandlerFunc {
|
func formHandler(filename string) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
tmpl, err := template.ParseFiles("forms.html")
|
tmpl, err := template.ParseFS(page, "forms.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue