fix: build only from Go version 1.7 onward
This commit is contained in:
parent
46220b726d
commit
70d0a4c5ba
31
gin.go
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
gin1.7.go
Normal file
40
gin1.7.go
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user