[Home]   [TOC]

Study_Security_TLS_GoLang  
Go lang security
Updated Oct 23, 2014 by jht5...@gmail.com

在Go语言中使用HTTPS:

import (
	"log"
	"net/http"
)

func handler(w http.ResponseWriter, req *http.Request) {
	w.Header().Set("Content-Type", "text/plain")
	w.Write([]byte("This is an example server.\n"))
}

func main() {
	http.HandleFunc("/", handler)
	log.Printf("About to listen on 10443. Go to https://127.0.0.1:10443/")
	err := http.ListenAndServeTLS(":10443", "cert.pem", "key.pem", nil)
	if err != nil {
		log.Fatal(err)
	}
}

参考资料

[1]. http://golang.org/pkg/net/http/#ListenAndServeTLS