If you don't use a cache you're just begging for Let's Encrypt to ban you for a week due to duplicate certificate requests. Don't encourage users to get banned. Change-Id: Icf999c7f28817990bb45931d30692d4040c0ed71 Reviewed-on: https://go-review.googlesource.com/66550 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Vaghin <ddos@google.com>
36 lines
851 B
Go
36 lines
851 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 (
|
|
"crypto/tls"
|
|
"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,
|
|
HostPolicy: autocert.HostWhitelist("example.org"),
|
|
}
|
|
s := &http.Server{
|
|
Addr: ":https",
|
|
TLSConfig: &tls.Config{GetCertificate: m.GetCertificate},
|
|
}
|
|
s.ListenAndServeTLS("", "")
|
|
}
|