h2server.go 893 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2014 The Go Authors.
  2. // See https://code.google.com/p/go/source/browse/CONTRIBUTORS
  3. // Licensed under the same terms as Go itself:
  4. // https://code.google.com/p/go/source/browse/LICENSE
  5. package main
  6. import (
  7. "fmt"
  8. "log"
  9. "net/http"
  10. "os/exec"
  11. "time"
  12. "github.com/bradfitz/http2"
  13. )
  14. func main() {
  15. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  16. fmt.Fprintf(w, "Hello world")
  17. })
  18. var srv http.Server
  19. log.Printf("Listening on https://localhost:4430/")
  20. srv.Addr = "localhost:4430"
  21. http2.ConfigureServer(&srv, &http2.Server{})
  22. closeFirefox()
  23. go func() {
  24. log.Fatal(srv.ListenAndServeTLS("server.crt", "server.key"))
  25. }()
  26. time.Sleep(500 * time.Millisecond)
  27. exec.Command("open", "-b", "org.mozilla.nightly", "https://localhost:4430/").Run()
  28. select {}
  29. }
  30. func closeFirefox() {
  31. exec.Command("open", "/Applications/CloseFirefoxNightly.app").Run()
  32. }