先生成ssl证书
openssl genrsa -out key.pem 2048 openssl req -new -x509 -key key.pem -out cert.pem -days 1095
然后,大概这样
package main import ( "log" "net/http" ) func SayHello(w http.ResponseWriter, req *http.Request) { w.Write([]byte("Hello")) } func main() { http.HandleFunc("/", SayHello) err := http.ListenAndServeTLS(":8080", "cert.pem", "key.pem", nil) if err != nil { log.Fatal("ListenAndServe: ", err) } }
附一个免费的ssl证书制造地方
http://zyan.cc/startssl/
时间: 2024-10-07 09:57:51