修改Go的SDK,支持同一个端口访问http自动跳转到https
项目地址:https://github.com/mzky/https
实际只改动了net/http/server.go文件
tlsBadRequest := `HTTP/1.0 200 OK
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>自动跳转到HTTPS</title>
<script type="text/javascript">
url = window.location.href.replace("http:", "https:");
window.location.replace(url);
</script>
</head>
<body>
</body>
</html>
`
k.Server = &http.Server{Addr: k.Addr, Handler: k.Engine, TlsBadRequest: tlsBadRequest}
if err := k.Server.ListenAndServeTLS(k.Config.ServerPem, k.Config.ServerKey); err != nil {
logrus.Fatalf("启动失败,检查端口是否被占用,TLS证书是否正常: %v", err)
}
修改$GOROOT/src/net/http/server.go文件后,编译程序和执行均正常,但将项目提交到github后,引用会报错,可能由于没有全部SDK上传导致gin.Engine无法识别为Handler