You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

37 lines
905 B

  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. Cache: autocert.DirCache("secret-dir"),
  22. Prompt: autocert.AcceptTOS,
  23. HostPolicy: autocert.HostWhitelist("example.org"),
  24. }
  25. go http.ListenAndServe(":http", m.HTTPHandler(nil))
  26. s := &http.Server{
  27. Addr: ":https",
  28. TLSConfig: &tls.Config{GetCertificate: m.GetCertificate},
  29. }
  30. s.ListenAndServeTLS("", "")
  31. }