func main() { flag.Parse() err := loadTemplates() if err != nil { log.Fatalln("loadTemplates:", err) } http.Handle("/favicon.ico/", http.NotFoundHandler()) http.Handle("/", http.HandlerFunc(mainHandler)) http.Handle("/websocket/", websocket.Handler(webSocketHandler)) http.Handle("/assets/", http.FileServer(http.Dir("./"))) http.Handle("/assets/script.go.js", gopherjs_http.StaticGoFiles("./assets/script.go")) err = http.ListenAndServe(*httpFlag, nil) if err != nil { log.Fatalln("ListenAndServe:", err) } }
func Test(t *testing.T) { http.Handle("/script.go.js", gopherjs_http.StaticGoFiles("./frontend.go")) { defaultValue := false queryParameter := "some-optional-thing" http.HandleFunc("/index.html", func(w http.ResponseWriter, req *http.Request) { query := req.URL.Query() checkboxHtml := checkbox.New(defaultValue, query, queryParameter) io.WriteString(w, `<html><head><script type="text/javascript" src="/script.go.js"></script></head><body>`+string(checkboxHtml)+"</body></html>") }) } ts := httptest.NewServer(nil) defer ts.Close() u4.Open(ts.URL + "/index.html") select {} }
func Test(t *testing.T) { http.Handle("/script.go.js", gopherjs_http.StaticGoFiles("./frontend.go")) { options := []string{"option one", "option two (default)", "option three", "option four", "option five"} defaultOption := "option two (default)" queryParameter := "parameter" http.HandleFunc("/index.html", func(w http.ResponseWriter, req *http.Request) { query := req.URL.Query() selectMenuHtml := select_menu.New(options, defaultOption, query, queryParameter) io.WriteString(w, `<html><head><script type="text/javascript" src="/script.go.js"></script></head><body>`+string(selectMenuHtml)+"</body></html>") }) } ts := httptest.NewServer(nil) defer ts.Close() u4.Open(ts.URL + "/index.html") select {} }