Package golang.org/x/crypto/acme/autocert example will not compile for me

trying to compile example code from acme/autocert package with go version OS X go1.9.2 darwin/amd64 and getting: m.HTTPHandler undefined (type *autocert.Manager has no field or method HTTPHandler)
I’m missing something obvious I’m sure? Code below will not compile for me. If I comment out the groutine ( line 17 or so ) I see two methods I expect but miss the HTTPHandler method…

package main

import (
	"crypto/tls"
	"fmt"
	"net/http"
	"reflect"

	"golang.org/x/crypto/acme/autocert"
)

func main() {
	m := &autocert.Manager{
		Cache:      autocert.DirCache("secret-dir"),
		Prompt:     autocert.AcceptTOS,
		HostPolicy: autocert.HostWhitelist("example.org"),
	}
	go http.ListenAndServe(":http", m.HTTPHandler(nil))
	s := &http.Server{
		Addr:      ":https",
		TLSConfig: &tls.Config{GetCertificate: m.GetCertificate},
	}
	s.ListenAndServeTLS("", "")

	// debug: list all method names of type = *autocert.Manager

	r := reflect.TypeOf(&autocert.Manager{})
	for i := 0; i < r.NumMethod(); i++ {
		fmt.Println(r.Method(i).Name)
	}

	//    prints GetCertificate Listener; yes but expected HTTPHandler also?

}

HTTPHandler is a new method added in https://go-review.googlesource.com/c/crypto/+/87201

Update to a newer version of autocert with:

go get -u golang.org/x/crypto/acme/autocert

BTW, I tested this yesterday when updating my article https://pocketgophers.com/serving-https/

that did it!… many thanks and enjoying your article…

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.