example_test.go 804 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2017 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package autocert_test
  5. import (
  6. "crypto/tls"
  7. "fmt"
  8. "log"
  9. "net/http"
  10. "golang.org/x/crypto/acme/autocert"
  11. )
  12. func ExampleNewListener() {
  13. mux := http.NewServeMux()
  14. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  15. fmt.Fprintf(w, "Hello, TLS user! Your config: %+v", r.TLS)
  16. })
  17. log.Fatal(http.Serve(autocert.NewListener("example.com"), mux))
  18. }
  19. func ExampleManager() {
  20. m := autocert.Manager{
  21. Prompt: autocert.AcceptTOS,
  22. HostPolicy: autocert.HostWhitelist("example.org"),
  23. }
  24. s := &http.Server{
  25. Addr: ":https",
  26. TLSConfig: &tls.Config{GetCertificate: m.GetCertificate},
  27. }
  28. s.ListenAndServeTLS("", "")
  29. }