版权声明:此文章转载自_infocool
原文链接:http://www.infocool.net/kb/Go/201609/188396.html
如需转载请联系听云College团队成员小尹 邮箱:yinhy#tingyun.com
1. 生成私钥
openssl genrsa -out key.pem 2048
2. 生成证书
openssl req -new -x509 -key key.pem -out cert.pem -days 1095
3. 服务端代码:
package main import ( "fmt" "log" "net/http" ) func test(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "this is a test for you") } func main() { http.HandleFunc("/test", test) err := http.ListenAndServeTLS(":8080", "cert.pem", "key.pem", nil) if err != nil { log.Fatal("ListenerAndServe:", err) } }