From 12c985af8526c1f6f0c463bbfd9d69623d13b323 Mon Sep 17 00:00:00 2001 From: Ross Light Date: Tue, 18 Apr 2017 09:56:57 -0700 Subject: [PATCH] acme/autocert: extract Manager example from comments Ensures that it compiles and makes it more discoverable in godoc. Change-Id: I50a3deb23110017d0eb16b1da0ac729a96ff2602 Reviewed-on: https://go-review.googlesource.com/40952 Run-TryBot: Alex Vaghin Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- acme/autocert/autocert.go | 12 ------------ acme/autocert/{listener_test.go => example_test.go} | 13 +++++++++++++ 2 files changed, 13 insertions(+), 12 deletions(-) rename acme/autocert/{listener_test.go => example_test.go} (63%) diff --git a/acme/autocert/autocert.go b/acme/autocert/autocert.go index f50c88e..7e388ff 100644 --- a/acme/autocert/autocert.go +++ b/acme/autocert/autocert.go @@ -77,18 +77,6 @@ func defaultHostPolicy(context.Context, string) error { // It obtains and refreshes certificates automatically, // as well as providing them to a TLS server via tls.Config. // -// A simple usage example: -// -// m := autocert.Manager{ -// Prompt: autocert.AcceptTOS, -// HostPolicy: autocert.HostWhitelist("example.org"), -// } -// s := &http.Server{ -// Addr: ":https", -// TLSConfig: &tls.Config{GetCertificate: m.GetCertificate}, -// } -// s.ListenAndServeTLS("", "") -// // To preserve issued certificates and improve overall performance, // use a cache implementation of Cache. For instance, DirCache. type Manager struct { diff --git a/acme/autocert/listener_test.go b/acme/autocert/example_test.go similarity index 63% rename from acme/autocert/listener_test.go rename to acme/autocert/example_test.go index 9272ebb..c6267b8 100644 --- a/acme/autocert/listener_test.go +++ b/acme/autocert/example_test.go @@ -5,6 +5,7 @@ package autocert_test import ( + "crypto/tls" "fmt" "log" "net/http" @@ -19,3 +20,15 @@ func ExampleNewListener() { }) log.Fatal(http.Serve(autocert.NewListener("example.com"), mux)) } + +func ExampleManager() { + m := autocert.Manager{ + Prompt: autocert.AcceptTOS, + HostPolicy: autocert.HostWhitelist("example.org"), + } + s := &http.Server{ + Addr: ":https", + TLSConfig: &tls.Config{GetCertificate: m.GetCertificate}, + } + s.ListenAndServeTLS("", "") +}