Forráskód Böngészése

fix: build only from Go version 1.7 onward

Bo-Yi Wu 8 éve
szülő
commit
70d0a4c5ba
2 módosított fájl, 40 hozzáadás és 31 törlés
  1. 0 31
      gin.go
  2. 40 0
      gin1.7.go

+ 0 - 31
gin.go

@@ -5,7 +5,6 @@
 package gin
 
 import (
-	"crypto/tls"
 	"html/template"
 	"net"
 	"net/http"
@@ -13,7 +12,6 @@ import (
 	"sync"
 
 	"github.com/gin-gonic/gin/render"
-	"golang.org/x/crypto/acme/autocert"
 )
 
 // Version is Framework's version
@@ -257,35 +255,6 @@ func (engine *Engine) RunTLS(addr string, certFile string, keyFile string) (err
 	return
 }
 
-// RunAutoTLS attaches the router to a http.Server and starts listening and serving HTTPS (secure) requests.
-// It obtains and refreshes certificates automatically,
-// as well as providing them to a TLS server via tls.Config.
-func (engine *Engine) RunAutoTLS(addr string, cache string, domain ...string) (err error) {
-	debugPrint("Listening and serving HTTPS on %s and host name is %s\n", addr, domain)
-	defer func() { debugPrintError(err) }()
-	m := autocert.Manager{
-		Prompt: autocert.AcceptTOS,
-	}
-
-	//your domain here
-	if len(domain) != 0 {
-		m.HostPolicy = autocert.HostWhitelist(domain...)
-	}
-
-	// folder for storing certificates
-	if cache != "" {
-		m.Cache = autocert.DirCache(cache)
-	}
-
-	s := &http.Server{
-		Addr:      addr,
-		TLSConfig: &tls.Config{GetCertificate: m.GetCertificate},
-		Handler:   engine,
-	}
-	err = s.ListenAndServeTLS("", "")
-	return
-}
-
 // RunUnix attaches the router to a http.Server and starts listening and serving HTTP requests
 // through the specified unix socket (ie. a file).
 // Note: this method will block the calling goroutine indefinitely unless an error happens.

+ 40 - 0
gin1.7.go

@@ -0,0 +1,40 @@
+// +build go1.7
+
+package gin
+
+import (
+	"crypto/tls"
+	"net/http"
+
+	"golang.org/x/crypto/acme/autocert"
+)
+
+// RunAutoTLS attaches the router to a http.Server and starts listening and serving HTTPS (secure) requests.
+// It obtains and refreshes certificates automatically,
+// as well as providing them to a TLS server via tls.Config.
+// only from Go version 1.7 onward
+func (engine *Engine) RunAutoTLS(addr string, cache string, domain ...string) (err error) {
+	debugPrint("Listening and serving HTTPS on %s and host name is %s\n", addr, domain)
+	defer func() { debugPrintError(err) }()
+	m := autocert.Manager{
+		Prompt: autocert.AcceptTOS,
+	}
+
+	//your domain here
+	if len(domain) != 0 {
+		m.HostPolicy = autocert.HostWhitelist(domain...)
+	}
+
+	// folder for storing certificates
+	if cache != "" {
+		m.Cache = autocert.DirCache(cache)
+	}
+
+	s := &http.Server{
+		Addr:      addr,
+		TLSConfig: &tls.Config{GetCertificate: m.GetCertificate},
+		Handler:   engine,
+	}
+	err = s.ListenAndServeTLS("", "")
+	return
+}