...

Source file src/golang.org/x/crypto/acme/autocert/example_test.go

Documentation: golang.org/x/crypto/acme/autocert

     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  	"fmt"
     9  	"log"
    10  	"net/http"
    11  
    12  	"golang.org/x/crypto/acme/autocert"
    13  )
    14  
    15  func ExampleNewListener() {
    16  	mux := http.NewServeMux()
    17  	mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    18  		fmt.Fprintf(w, "Hello, TLS user! Your config: %+v", r.TLS)
    19  	})
    20  	log.Fatal(http.Serve(autocert.NewListener("example.com"), mux))
    21  }
    22  
    23  func ExampleManager() {
    24  	m := &autocert.Manager{
    25  		Cache:      autocert.DirCache("secret-dir"),
    26  		Prompt:     autocert.AcceptTOS,
    27  		Email:      "example@example.org",
    28  		HostPolicy: autocert.HostWhitelist("example.org", "www.example.org"),
    29  	}
    30  	s := &http.Server{
    31  		Addr:      ":https",
    32  		TLSConfig: m.TLSConfig(),
    33  	}
    34  	s.ListenAndServeTLS("", "")
    35  }
    36  

View as plain text