Brad Fitzpatrick | b020702 | 2017-04-02 16:08:48 -0700 | [diff] [blame] | 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 | |
| 5 | package autocert_test |
| 6 | |
| 7 | import ( |
Ross Light | 12c985a | 2017-04-18 09:56:57 -0700 | [diff] [blame] | 8 | "crypto/tls" |
Brad Fitzpatrick | b020702 | 2017-04-02 16:08:48 -0700 | [diff] [blame] | 9 | "fmt" |
| 10 | "log" |
| 11 | "net/http" |
| 12 | |
| 13 | "golang.org/x/crypto/acme/autocert" |
| 14 | ) |
| 15 | |
| 16 | func ExampleNewListener() { |
| 17 | mux := http.NewServeMux() |
| 18 | mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 19 | fmt.Fprintf(w, "Hello, TLS user! Your config: %+v", r.TLS) |
| 20 | }) |
| 21 | log.Fatal(http.Serve(autocert.NewListener("example.com"), mux)) |
| 22 | } |
Ross Light | 12c985a | 2017-04-18 09:56:57 -0700 | [diff] [blame] | 23 | |
| 24 | func ExampleManager() { |
| 25 | m := autocert.Manager{ |
| 26 | Prompt: autocert.AcceptTOS, |
| 27 | HostPolicy: autocert.HostWhitelist("example.org"), |
| 28 | } |
| 29 | s := &http.Server{ |
| 30 | Addr: ":https", |
| 31 | TLSConfig: &tls.Config{GetCertificate: m.GetCertificate}, |
| 32 | } |
| 33 | s.ListenAndServeTLS("", "") |
| 34 | } |