At Let's Encrypt, we've found that most autocert users do not provide an email address, which makes it hard to get in touch when things go wrong with their client. Demonstrating how to provide an email will probably encourage more people to provide one. Change-Id: I0aa1ecea7cfbe55ae155804194fb57a8e695c658 GitHub-Last-Rev: 902b5fe2682a6be5af91e886272fd680fd67a94e GitHub-Pull-Request: golang/crypto#186 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/323313 Reviewed-by: Roland Shoemaker <roland@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Katie Hockman <katie@golang.org> Trust: Katie Hockman <katie@golang.org>
36 lines
862 B
Go
36 lines
862 B
Go
// Copyright 2017 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package autocert_test
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
|
|
"golang.org/x/crypto/acme/autocert"
|
|
)
|
|
|
|
func ExampleNewListener() {
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprintf(w, "Hello, TLS user! Your config: %+v", r.TLS)
|
|
})
|
|
log.Fatal(http.Serve(autocert.NewListener("example.com"), mux))
|
|
}
|
|
|
|
func ExampleManager() {
|
|
m := &autocert.Manager{
|
|
Cache: autocert.DirCache("secret-dir"),
|
|
Prompt: autocert.AcceptTOS,
|
|
Email: "example@example.org",
|
|
HostPolicy: autocert.HostWhitelist("example.org", "www.example.org"),
|
|
}
|
|
s := &http.Server{
|
|
Addr: ":https",
|
|
TLSConfig: m.TLSConfig(),
|
|
}
|
|
s.ListenAndServeTLS("", "")
|
|
}
|