Golang HTTPS
发布时间:2020-12-16 19:13:52 所属栏目:大数据 来源:网络整理
导读:用 golang 来实现的 webserver 通常是是这样的 //main.gopackage mainimport ("fmt""io""net/http")func defaultHandler(w http.ResponseWriter,r *http.Request) {io.WriteString(w,"h1Golang HTTP/h1")}func main() {mux := http.NewServeMux()mux.HandleF
用 //main.go package main import ( "fmt" "io" "net/http" ) func defaultHandler(w http.ResponseWriter,r *http.Request) { io.WriteString(w,"<h1>Golang HTTP</h1>") } func main() { mux := http.NewServeMux() mux.HandleFunc("/",defaultHandler) err := http.ListenAndServe(":80",mux) if err != nil { fmt.Println(err.Error()) } } 服务运行后,我们通常通过 那么如何用 //main.go package main import ( "fmt" "io" "net/http" ) func defaultHandler(w http.ResponseWriter,"<h1>Golang HTTPS</h1>") } func main() { mux := http.NewServeMux() mux.HandleFunc("/",defaultHandler) certFile := "/etc/letsencrypt/live/www.taadis.com/cert.pem" keyFile := "/etc/letsencrypt/live/www.taadis.com/privkey.pem" err := http.ListenAndServeTLS(":443",certFile,keyFile,mux) if err != nil { fmt.Println(err.Error()) } } 源码比较简单, (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |