example_test.go 825 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. "fmt"
  7. "log"
  8. "net/http"
  9. "golang.org/x/crypto/acme/autocert"
  10. )
  11. func ExampleNewListener() {
  12. mux := http.NewServeMux()
  13. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  14. fmt.Fprintf(w, "Hello, TLS user! Your config: %+v", r.TLS)
  15. })
  16. log.Fatal(http.Serve(autocert.NewListener("example.com"), mux))
  17. }
  18. func ExampleManager() {
  19. m := &autocert.Manager{
  20. Cache: autocert.DirCache("secret-dir"),
  21. Prompt: autocert.AcceptTOS,
  22. HostPolicy: autocert.HostWhitelist("example.org", "www.example.org"),
  23. }
  24. s := &http.Server{
  25. Addr: ":https",
  26. TLSConfig: m.TLSConfig(),
  27. }
  28. s.ListenAndServeTLS("", "")
  29. }