67
67
// Echo is the top-level framework instance.
68
68
Echo struct {
69
69
common
70
- // startupMu is mutex to lock Echo instance access during server configuration and startup. Useful for to get
70
+ // startupMutex is mutex to lock Echo instance access during server configuration and startup. Useful for to get
71
71
// listener address info (on which interface/port was listener binded) without having data races.
72
- startupMu sync.RWMutex
72
+ startupMutex sync.RWMutex
73
73
StdLogger * stdLog.Logger
74
74
colorer * color.Color
75
75
premiddleware []MiddlewareFunc
@@ -646,47 +646,47 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
646
646
647
647
// Start starts an HTTP server.
648
648
func (e * Echo ) Start (address string ) error {
649
- e .startupMu .Lock ()
649
+ e .startupMutex .Lock ()
650
650
e .Server .Addr = address
651
651
if err := e .configureServer (e .Server ); err != nil {
652
- e .startupMu .Unlock ()
652
+ e .startupMutex .Unlock ()
653
653
return err
654
654
}
655
- e .startupMu .Unlock ()
655
+ e .startupMutex .Unlock ()
656
656
return e .serve ()
657
657
}
658
658
659
659
// StartTLS starts an HTTPS server.
660
660
// If `certFile` or `keyFile` is `string` the values are treated as file paths.
661
661
// If `certFile` or `keyFile` is `[]byte` the values are treated as the certificate or key as-is.
662
662
func (e * Echo ) StartTLS (address string , certFile , keyFile interface {}) (err error ) {
663
- e .startupMu .Lock ()
663
+ e .startupMutex .Lock ()
664
664
var cert []byte
665
665
if cert , err = filepathOrContent (certFile ); err != nil {
666
- e .startupMu .Unlock ()
666
+ e .startupMutex .Unlock ()
667
667
return
668
668
}
669
669
670
670
var key []byte
671
671
if key , err = filepathOrContent (keyFile ); err != nil {
672
- e .startupMu .Unlock ()
672
+ e .startupMutex .Unlock ()
673
673
return
674
674
}
675
675
676
676
s := e .TLSServer
677
677
s .TLSConfig = new (tls.Config )
678
678
s .TLSConfig .Certificates = make ([]tls.Certificate , 1 )
679
679
if s .TLSConfig .Certificates [0 ], err = tls .X509KeyPair (cert , key ); err != nil {
680
- e .startupMu .Unlock ()
680
+ e .startupMutex .Unlock ()
681
681
return
682
682
}
683
683
684
684
e .configureTLS (address )
685
685
if err := e .configureServer (s ); err != nil {
686
- e .startupMu .Unlock ()
686
+ e .startupMutex .Unlock ()
687
687
return err
688
688
}
689
- e .startupMu .Unlock ()
689
+ e .startupMutex .Unlock ()
690
690
return s .Serve (e .TLSListener )
691
691
}
692
692
@@ -703,18 +703,18 @@ func filepathOrContent(fileOrContent interface{}) (content []byte, err error) {
703
703
704
704
// StartAutoTLS starts an HTTPS server using certificates automatically installed from https://letsencrypt.org.
705
705
func (e * Echo ) StartAutoTLS (address string ) error {
706
- e .startupMu .Lock ()
706
+ e .startupMutex .Lock ()
707
707
s := e .TLSServer
708
708
s .TLSConfig = new (tls.Config )
709
709
s .TLSConfig .GetCertificate = e .AutoTLSManager .GetCertificate
710
710
s .TLSConfig .NextProtos = append (s .TLSConfig .NextProtos , acme .ALPNProto )
711
711
712
712
e .configureTLS (address )
713
713
if err := e .configureServer (s ); err != nil {
714
- e .startupMu .Unlock ()
714
+ e .startupMutex .Unlock ()
715
715
return err
716
716
}
717
- e .startupMu .Unlock ()
717
+ e .startupMutex .Unlock ()
718
718
return s .Serve (e .TLSListener )
719
719
}
720
720
@@ -728,12 +728,12 @@ func (e *Echo) configureTLS(address string) {
728
728
729
729
// StartServer starts a custom http server.
730
730
func (e * Echo ) StartServer (s * http.Server ) (err error ) {
731
- e .startupMu .Lock ()
731
+ e .startupMutex .Lock ()
732
732
if err := e .configureServer (s ); err != nil {
733
- e .startupMu .Unlock ()
733
+ e .startupMutex .Unlock ()
734
734
return err
735
735
}
736
- e .startupMu .Unlock ()
736
+ e .startupMutex .Unlock ()
737
737
return e .serve ()
738
738
}
739
739
@@ -784,8 +784,8 @@ func (e *Echo) serve() error {
784
784
785
785
// ListenerAddr returns net.Addr for Listener
786
786
func (e * Echo ) ListenerAddr () net.Addr {
787
- e .startupMu .RLock ()
788
- defer e .startupMu .RUnlock ()
787
+ e .startupMutex .RLock ()
788
+ defer e .startupMutex .RUnlock ()
789
789
if e .Listener == nil {
790
790
return nil
791
791
}
@@ -794,8 +794,8 @@ func (e *Echo) ListenerAddr() net.Addr {
794
794
795
795
// TLSListenerAddr returns net.Addr for TLSListener
796
796
func (e * Echo ) TLSListenerAddr () net.Addr {
797
- e .startupMu .RLock ()
798
- defer e .startupMu .RUnlock ()
797
+ e .startupMutex .RLock ()
798
+ defer e .startupMutex .RUnlock ()
799
799
if e .TLSListener == nil {
800
800
return nil
801
801
}
@@ -804,7 +804,7 @@ func (e *Echo) TLSListenerAddr() net.Addr {
804
804
805
805
// StartH2CServer starts a custom http/2 server with h2c (HTTP/2 Cleartext).
806
806
func (e * Echo ) StartH2CServer (address string , h2s * http2.Server ) (err error ) {
807
- e .startupMu .Lock ()
807
+ e .startupMutex .Lock ()
808
808
// Setup
809
809
s := e .Server
810
810
s .Addr = address
@@ -822,22 +822,22 @@ func (e *Echo) StartH2CServer(address string, h2s *http2.Server) (err error) {
822
822
if e .Listener == nil {
823
823
e .Listener , err = newListener (s .Addr , e .ListenerNetwork )
824
824
if err != nil {
825
- e .startupMu .Unlock ()
825
+ e .startupMutex .Unlock ()
826
826
return err
827
827
}
828
828
}
829
829
if ! e .HidePort {
830
830
e .colorer .Printf ("⇨ http server started on %s\n " , e .colorer .Green (e .Listener .Addr ()))
831
831
}
832
- e .startupMu .Unlock ()
832
+ e .startupMutex .Unlock ()
833
833
return s .Serve (e .Listener )
834
834
}
835
835
836
836
// Close immediately stops the server.
837
837
// It internally calls `http.Server#Close()`.
838
838
func (e * Echo ) Close () error {
839
- e .startupMu .Lock ()
840
- defer e .startupMu .Unlock ()
839
+ e .startupMutex .Lock ()
840
+ defer e .startupMutex .Unlock ()
841
841
if err := e .TLSServer .Close (); err != nil {
842
842
return err
843
843
}
@@ -847,8 +847,8 @@ func (e *Echo) Close() error {
847
847
// Shutdown stops the server gracefully.
848
848
// It internally calls `http.Server#Shutdown()`.
849
849
func (e * Echo ) Shutdown (ctx stdContext.Context ) error {
850
- e .startupMu .Lock ()
851
- defer e .startupMu .Unlock ()
850
+ e .startupMutex .Lock ()
851
+ defer e .startupMutex .Unlock ()
852
852
if err := e .TLSServer .Shutdown (ctx ); err != nil {
853
853
return err
854
854
}
0 commit comments