go语言使用SSL证书

package main

import (
    "log"
    "net/http"
)

// 测试go语言证书访问
// openssl genrsa -out server.key 2048
// openssl req -nodes -new -key server.key -subj "/CN=localhost" -out server.csr
// openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt

func main() {

    http.HandleFunc("/ssl", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("hello world"))
    })

    // 运行
    if err := http.ListenAndServeTLS(":9000", "", "", nil); err != nil {
        log.Fatal("ListenAndServe: ", err)
    }
}


你可能感兴趣的:(go语言使用SSL证书)