Because tls.Config now requires more fields to be set in order for tls-alpn to work, Manager provides a new TLSConfig method for easier setup. This CL also adds a new internal package for end-to-end tests. The package implements a simple ACME CA server. Fixes golang/go#25013 Fixes golang/go#25901 Updates golang/go#17251 Change-Id: I2687ea8d5c445ddafad5ea2cdd36cd4e7d10bc86 Reviewed-on: https://go-review.googlesource.com/125495 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
35 lines
806 B
Go
35 lines
806 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 (
|
|
"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: m.TLSConfig(),
|
|
}
|
|
s.ListenAndServeTLS("", "")
|
|
}
|