mirror of
https://github.com/labstack/echo.git
synced 2025-01-12 01:22:21 +02:00
parent
73110004ef
commit
8d504c1b69
15
echo.go
15
echo.go
@ -52,8 +52,8 @@ import (
|
|||||||
|
|
||||||
"github.com/labstack/gommon/color"
|
"github.com/labstack/gommon/color"
|
||||||
glog "github.com/labstack/gommon/log"
|
glog "github.com/labstack/gommon/log"
|
||||||
"github.com/rsc/letsencrypt"
|
|
||||||
"github.com/tylerb/graceful"
|
"github.com/tylerb/graceful"
|
||||||
|
"golang.org/x/crypto/acme/autocert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -64,12 +64,12 @@ type (
|
|||||||
HTTPErrorHandler
|
HTTPErrorHandler
|
||||||
Binder Binder
|
Binder Binder
|
||||||
Renderer Renderer
|
Renderer Renderer
|
||||||
|
AutoTLSManager autocert.Manager
|
||||||
ShutdownTimeout time.Duration
|
ShutdownTimeout time.Duration
|
||||||
Color *color.Color
|
Color *color.Color
|
||||||
Logger Logger
|
Logger Logger
|
||||||
server *graceful.Server
|
server *graceful.Server
|
||||||
tlsServer *graceful.Server
|
tlsServer *graceful.Server
|
||||||
tlsManager letsencrypt.Manager
|
|
||||||
premiddleware []MiddlewareFunc
|
premiddleware []MiddlewareFunc
|
||||||
middleware []MiddlewareFunc
|
middleware []MiddlewareFunc
|
||||||
maxParam *int
|
maxParam *int
|
||||||
@ -236,6 +236,9 @@ var (
|
|||||||
// New creates an instance of Echo.
|
// New creates an instance of Echo.
|
||||||
func New() (e *Echo) {
|
func New() (e *Echo) {
|
||||||
e = &Echo{
|
e = &Echo{
|
||||||
|
AutoTLSManager: autocert.Manager{
|
||||||
|
Prompt: autocert.AcceptTOS,
|
||||||
|
},
|
||||||
ShutdownTimeout: 15 * time.Second,
|
ShutdownTimeout: 15 * time.Second,
|
||||||
Logger: glog.New("echo"),
|
Logger: glog.New("echo"),
|
||||||
maxParam: new(int),
|
maxParam: new(int),
|
||||||
@ -520,13 +523,9 @@ func (e *Echo) StartTLS(address string, certFile, keyFile string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StartAutoTLS starts the HTTPS server using certificates automatically from https://letsencrypt.org.
|
// StartAutoTLS starts the HTTPS server using certificates automatically from https://letsencrypt.org.
|
||||||
func (e *Echo) StartAutoTLS(address string, hosts []string, cacheFile string) (err error) {
|
func (e *Echo) StartAutoTLS(address string) error {
|
||||||
config := new(tls.Config)
|
config := new(tls.Config)
|
||||||
config.GetCertificate = e.tlsManager.GetCertificate
|
config.GetCertificate = e.AutoTLSManager.GetCertificate
|
||||||
e.tlsManager.SetHosts(hosts) // Added security
|
|
||||||
if err = e.tlsManager.CacheFile(cacheFile); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return e.startTLS(address, config)
|
return e.startTLS(address, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
52
glide.lock
generated
52
glide.lock
generated
@ -1,65 +1,54 @@
|
|||||||
hash: d63c27ff06a540317f63f231ada71f3d03f1c09e79a2c47b29b43c654903fc8b
|
hash: c3a41d26c94d8101a2aeaea5bc438cb75c5e9b7bd80850c7ec806c00c535d1c7
|
||||||
updated: 2016-11-21T19:12:16.622618752-08:00
|
updated: 2016-12-02T08:49:24.85691-08:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/daaku/go.zipexe
|
- name: github.com/daaku/go.zipexe
|
||||||
version: a5fe2436ffcb3236e175e5149162b41cd28bd27d
|
version: a5fe2436ffcb3236e175e5149162b41cd28bd27d
|
||||||
- name: github.com/dgrijalva/jwt-go
|
- name: github.com/dgrijalva/jwt-go
|
||||||
version: 24c63f56522a87ec5339cc3567883f1039378fdb
|
version: 9ed569b5d1ac936e6494082958d63a6aa4fff99a
|
||||||
- name: github.com/GeertJohan/go.rice
|
- name: github.com/GeertJohan/go.rice
|
||||||
version: 9fdfd46f9806a9228aae341d65ab75c5235c383c
|
version: 9fdfd46f9806a9228aae341d65ab75c5235c383c
|
||||||
subpackages:
|
subpackages:
|
||||||
- embedded
|
- embedded
|
||||||
- name: github.com/golang/protobuf
|
- name: github.com/golang/protobuf
|
||||||
version: 98fa357170587e470c5f27d3c3ea0947b71eb455
|
version: 8ee79997227bf9b34611aee7946ae64735e6fd93
|
||||||
subpackages:
|
subpackages:
|
||||||
- proto
|
- proto
|
||||||
- name: github.com/gorilla/websocket
|
- name: github.com/gorilla/websocket
|
||||||
version: 0b847f2facc24ec406130a05bb1bb72d41993b05
|
version: e8f0f8aaa98dfb6586cbdf2978d511e3199a960a
|
||||||
- name: github.com/kardianos/osext
|
- name: github.com/kardianos/osext
|
||||||
version: c2c54e542fb797ad986b31721e1baedf214ca413
|
version: c2c54e542fb797ad986b31721e1baedf214ca413
|
||||||
- name: github.com/labstack/gommon
|
- name: github.com/labstack/gommon
|
||||||
version: 2d272df536d051e737aea353b86c979d6e88bce0
|
version: 447fe7433567c785af957e549aadae2bf2000071
|
||||||
subpackages:
|
subpackages:
|
||||||
- bytes
|
- bytes
|
||||||
- color
|
- color
|
||||||
- log
|
- log
|
||||||
- random
|
- random
|
||||||
- name: github.com/mattn/go-colorable
|
- name: github.com/mattn/go-colorable
|
||||||
version: 6c903ff4aa50920ca86087a280590b36b3152b9c
|
version: d228849504861217f796da67fae4f6e347643f15
|
||||||
- name: github.com/mattn/go-isatty
|
- name: github.com/mattn/go-isatty
|
||||||
version: 66b8e73f3f5cda9f96b69efd03dd3d7fc4a5cdb8
|
version: 30a891c33c7cde7b02a981314b4228ec99380cca
|
||||||
- name: github.com/miekg/dns
|
|
||||||
version: 58f52c57ce9df13460ac68200cef30a008b9c468
|
|
||||||
- name: github.com/rsc/letsencrypt
|
|
||||||
version: 76104d26167d38b6a0010f42bfc8ec5487742e8b
|
|
||||||
- name: github.com/tylerb/graceful
|
- name: github.com/tylerb/graceful
|
||||||
version: 50a48b6e73fcc75b45e22c05b79629a67c79e938
|
version: 4df1190835320af7076dfcf27b3d071fd3612caf
|
||||||
- name: github.com/valyala/fasttemplate
|
- name: github.com/valyala/fasttemplate
|
||||||
version: 3b874956e03f1636d171bda64b130f9135f42cff
|
version: 3b874956e03f1636d171bda64b130f9135f42cff
|
||||||
- name: github.com/xenolf/lego
|
- name: golang.org/x/crypto
|
||||||
version: 4bb8bea031eb805f361c04ca222f266b9e7feced
|
version: 8a549a1948fc5271eb24f36dcb0d3b47dec75a16
|
||||||
subpackages:
|
subpackages:
|
||||||
- acme
|
- acme
|
||||||
- name: golang.org/x/crypto
|
- acme/autocert
|
||||||
version: ca7e7f10cb9fd9c1a6ff7f60436c086d73714180
|
|
||||||
subpackages:
|
|
||||||
- ocsp
|
|
||||||
- name: golang.org/x/net
|
- name: golang.org/x/net
|
||||||
version: 65dfc08770ce66f74becfdff5f8ab01caef4e946
|
version: 97edce0b2e423f6a8debb459af47f4a3cb4ff954
|
||||||
subpackages:
|
subpackages:
|
||||||
- context
|
- context
|
||||||
- publicsuffix
|
- context/ctxhttp
|
||||||
- websocket
|
- websocket
|
||||||
- name: golang.org/x/sys
|
- name: golang.org/x/sys
|
||||||
version: c200b10b5d5e122be351b67af224adc6128af5bf
|
version: ca83bd2cb9abb47839b50eb4da612f00158f5870
|
||||||
subpackages:
|
subpackages:
|
||||||
- unix
|
- unix
|
||||||
- name: golang.org/x/time
|
|
||||||
version: 711ca1cb87636abec28122ef3bc6a77269d433f3
|
|
||||||
subpackages:
|
|
||||||
- rate
|
|
||||||
- name: google.golang.org/appengine
|
- name: google.golang.org/appengine
|
||||||
version: 5b8c3b819891014a2d12354528f7d046dd53c89e
|
version: ca59ef35f409df61fa4a5f8290ff289b37eccfb8
|
||||||
subpackages:
|
subpackages:
|
||||||
- internal
|
- internal
|
||||||
- internal/app_identity
|
- internal/app_identity
|
||||||
@ -68,14 +57,9 @@ imports:
|
|||||||
- internal/log
|
- internal/log
|
||||||
- internal/modules
|
- internal/modules
|
||||||
- internal/remote_api
|
- internal/remote_api
|
||||||
- name: gopkg.in/square/go-jose.v1
|
|
||||||
version: aa2e30fdd1fe9dd3394119af66451ae790d50e0d
|
|
||||||
subpackages:
|
|
||||||
- cipher
|
|
||||||
- json
|
|
||||||
testImports:
|
testImports:
|
||||||
- name: github.com/davecgh/go-spew
|
- name: github.com/davecgh/go-spew
|
||||||
version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9
|
version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9
|
||||||
subpackages:
|
subpackages:
|
||||||
- spew
|
- spew
|
||||||
- name: github.com/pmezard/go-difflib
|
- name: github.com/pmezard/go-difflib
|
||||||
@ -83,6 +67,6 @@ testImports:
|
|||||||
subpackages:
|
subpackages:
|
||||||
- difflib
|
- difflib
|
||||||
- name: github.com/stretchr/testify
|
- name: github.com/stretchr/testify
|
||||||
version: 976c720a22c8eb4eb6a0b4348ad85ad12491a506
|
version: 18a02ba4a312f95da08ff4cfc0055750ce50ae9e
|
||||||
subpackages:
|
subpackages:
|
||||||
- assert
|
- assert
|
||||||
|
@ -10,9 +10,11 @@ import:
|
|||||||
- log
|
- log
|
||||||
- random
|
- random
|
||||||
- package: github.com/mattn/go-isatty
|
- package: github.com/mattn/go-isatty
|
||||||
- package: github.com/rsc/letsencrypt
|
|
||||||
- package: github.com/tylerb/graceful
|
- package: github.com/tylerb/graceful
|
||||||
- package: github.com/valyala/fasttemplate
|
- package: github.com/valyala/fasttemplate
|
||||||
|
- package: golang.org/x/crypto
|
||||||
|
subpackages:
|
||||||
|
- acme/autocert
|
||||||
- package: golang.org/x/net
|
- package: golang.org/x/net
|
||||||
subpackages:
|
subpackages:
|
||||||
- websocket
|
- websocket
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
|
// e.AutoTLSManager.HostPolicy = autocert.HostWhitelist("<your_domain>")
|
||||||
e.Use(middleware.Recover())
|
e.Use(middleware.Recover())
|
||||||
e.Use(middleware.Logger())
|
e.Use(middleware.Logger())
|
||||||
e.GET("/", func(c echo.Context) error {
|
e.GET("/", func(c echo.Context) error {
|
||||||
@ -17,5 +18,5 @@ func main() {
|
|||||||
<h3>TLS certificates automatically installed from Let's Encrypt :)</h3>
|
<h3>TLS certificates automatically installed from Let's Encrypt :)</h3>
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
e.StartAutoTLS(":443", []string{"<your_domain>"}, "le.cache")
|
e.StartAutoTLS(":443")
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,14 @@ description = "Automatic TLS certificates from Let's Encrypt example for Echo"
|
|||||||
+++
|
+++
|
||||||
|
|
||||||
This recipe shows how to obtain TLS certificates for a domain automatically from
|
This recipe shows how to obtain TLS certificates for a domain automatically from
|
||||||
Let's Encrypt. `Echo#StartAutoTLS` accepts address which should listen on port `443`,
|
Let's Encrypt. `Echo#StartAutoTLS` accepts an address which should listen on port `443`.
|
||||||
list of host names for security and a file path to cache the certificates.
|
|
||||||
|
|
||||||
Browse to https://<your_domain>. If everything goes fine, you should see a welcome
|
Browse to `https://<your_domain>`. If everything goes fine, you should see a welcome
|
||||||
message with TLS enabled on the website.
|
message with TLS enabled on the website.
|
||||||
|
|
||||||
> To redirect HTTP traffic to HTTPS, you can use [redirect middleware](/middleware/redirect#https-redirect)
|
>
|
||||||
|
- For added security you should specify host policy in auto TLS manage
|
||||||
|
- To redirect HTTP traffic to HTTPS, you can use [redirect middleware](/middleware/redirect#https-redirect)
|
||||||
|
|
||||||
## Server
|
## Server
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user