GO語言"net/http"包中"ListenAndServeTLS"函數的用法及代碼示例。
用法:
func ListenAndServeTLS(addr, certFile, keyFile string, handler Handler) error
ListenAndServeTLS 的行為與 ListenAndServe 相同,隻是它需要 HTTPS 連接。此外,必須提供包含服務器證書和匹配私鑰的文件。如果證書由證書頒發機構簽名,則 certFile 應該是服務器證書、任何中間體和 CA 證書的串聯。
例子:
package main
import (
"io"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "Hello, TLS!\n")
})
// One can use generate_cert.go in crypto/tls to generate cert.pem and key.pem.
log.Printf("About to listen on 8443. Go to https://127.0.0.1:8443/")
err := http.ListenAndServeTLS(":8443", "cert.pem", "key.pem", nil)
log.Fatal(err)
}
相關用法
- GO ListenAndServe用法及代碼示例
- GO Listener用法及代碼示例
- GO LimitReader用法及代碼示例
- GO LeadingZeros32用法及代碼示例
- GO Logger.Output用法及代碼示例
- GO LastIndex用法及代碼示例
- GO Log10用法及代碼示例
- GO Log用法及代碼示例
- GO LeadingZeros8用法及代碼示例
- GO LeadingZeros16用法及代碼示例
- GO LastIndexAny用法及代碼示例
- GO Logger用法及代碼示例
- GO Len8用法及代碼示例
- GO LoadLocation用法及代碼示例
- GO LastIndexFunc用法及代碼示例
- GO Len64用法及代碼示例
- GO LoadX509KeyPair用法及代碼示例
- GO LookPath用法及代碼示例
- GO LookupEnv用法及代碼示例
- GO Len32用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 ListenAndServeTLS。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。