h2server.go 694 B

12345678910111213141516171819202122232425262728293031323334
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net/http"
  6. "os/exec"
  7. "time"
  8. "github.com/bradfitz/http2"
  9. )
  10. func main() {
  11. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  12. fmt.Fprintf(w, "Hello world")
  13. })
  14. var srv http.Server
  15. log.Printf("Listening on https://localhost:4430/")
  16. srv.Addr = "localhost:4430"
  17. http2.ConfigureServer(&srv, &http2.Server{})
  18. closeFirefox()
  19. go func() {
  20. log.Fatal(srv.ListenAndServeTLS("server.crt", "server.key"))
  21. }()
  22. time.Sleep(500 * time.Millisecond)
  23. exec.Command("open", "-b", "org.mozilla.nightly", "https://localhost:4430/").Run()
  24. select {}
  25. }
  26. func closeFirefox() {
  27. exec.Command("open", "/Applications/CloseFirefoxNightly.app").Run()
  28. }