// Package handlers. package handlers import ( "fmt" "net/http" "strings" ) // HTML handler. type HTML struct { Template []byte } // NewHTML returns new HTML handler. func NewHTML(width, height float64, nogl bool) *HTML { h := &HTML{} tpl := htmlWebGL if nogl { tpl = html } tpl = strings.Replace(tpl, "{WIDTH}", fmt.Sprintf("%.0f", width), -1) tpl = strings.Replace(tpl, "{HEIGHT}", fmt.Sprintf("%.0f", height), -1) h.Template = []byte(tpl) return h } // ServeHTTP handles requests on incoming connections. func (h *HTML) ServeHTTP(w http.ResponseWriter, r *http.Request) { if r.Method != "GET" && r.Method != "HEAD" { msg := fmt.Sprintf("405 Method Not Allowed (%s)", r.Method) http.Error(w, msg, http.StatusMethodNotAllowed) return } w.Header().Set("Content-Type", "text/html; charset=utf-8") w.WriteHeader(http.StatusOK) _, _ = w.Write(h.Template) } var html = `