生成key.pem和cert.pem:
openssl req -new -x509 -key key.pem -out cert.pem -days 1095
package main
import (
"fmt"
// "io/ioutil"
"net/http"
"log"
)
func main() {
http.HandleFunc( "/", makeHandler )
err := http.ListenAndServeTLS( ":8080", "cert.pem", "key.pem", nil
)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
这样编译运行后,就可以通过 https://localhost:8080/ 来访问了。
有疑问加站长微信联系(非本文作者)