This repository has been archived on 2021-01-15. You can view files and clone it, but cannot push or open issues or pull requests.
goBug/html.go

35 lines
820 B
Go

package main
import (
"html/template"
"net/http"
)
var varmap map[string]interface{}
// ServiHTML fa partire il server html
func ServiHTML() {
varmap = map[string]interface{}{
"matrice": Matrix,
"tempoAggiorna": Clock,
"larghezza": Larghezza,
"altezza": Altezza,
}
http.HandleFunc("/tabella", handlerRoot("template/tabella.html"))
http.HandleFunc("/", handlerRoot("template/Interfaccia.html"))
fs := http.FileServer(http.Dir("static"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
http.ListenAndServe(":3000", nil)
}
func handlerRoot(path string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
templ, err := template.ParseFiles(path)
if err != nil {
panic(err.Error())
}
templ.Execute(w, varmap)
}
}