OSDN Git Service

Hulk did something
[bytom/vapor.git] / vendor / golang.org / x / crypto / acme / autocert / example_test.go
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 (
8         "crypto/tls"
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 }
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 }