package main
import (
“crypto/tls”
“fmt”
“io”
“net/http”
)
func main() {
http.HandleFunc(“/”, handler)
s := &http.Server{
Addr: “:8080”,
TLSConfig: &tls.Config{
GetCertificate: getCertificate,
},
}
if err := s.ListenAndServeTLS(“”, “”); err != nil {
fmt.Println(err)
}
}
func getCertificate(info *tls.ClientHelloInfo) (*tls.Certificate, error) {
fmt.Println(“GetCertificate() called!”)
fmt.Printf(“ServerName: %s\n”, info.ServerName)
caFiles, err := tls.LoadX509KeyPair(“cert.pem”, “key.pem”)
if err != nil {
return nil, err
}
return &caFiles, nil
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Println(“handler hit”)
io.WriteString(w, “Hey”)
}