blob: c6267b8dd605810104f77a22cbf07a423d6d15de [file] [log] [blame]
Brad Fitzpatrickb0207022017-04-02 16:08:48 -07001// 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
5package autocert_test
6
7import (
Ross Light12c985a2017-04-18 09:56:57 -07008 "crypto/tls"
Brad Fitzpatrickb0207022017-04-02 16:08:48 -07009 "fmt"
10 "log"
11 "net/http"
12
13 "golang.org/x/crypto/acme/autocert"
14)
15
16func 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 Light12c985a2017-04-18 09:56:57 -070023
24func 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}