Skip to content

Commit d18c040

Browse files
committed
rename mutex
1 parent 734e313 commit d18c040

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

echo.go

+28-28
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ type (
6767
// Echo is the top-level framework instance.
6868
Echo struct {
6969
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
7171
// listener address info (on which interface/port was listener binded) without having data races.
72-
startupMu sync.RWMutex
72+
startupMutex sync.RWMutex
7373
StdLogger *stdLog.Logger
7474
colorer *color.Color
7575
premiddleware []MiddlewareFunc
@@ -646,47 +646,47 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
646646

647647
// Start starts an HTTP server.
648648
func (e *Echo) Start(address string) error {
649-
e.startupMu.Lock()
649+
e.startupMutex.Lock()
650650
e.Server.Addr = address
651651
if err := e.configureServer(e.Server); err != nil {
652-
e.startupMu.Unlock()
652+
e.startupMutex.Unlock()
653653
return err
654654
}
655-
e.startupMu.Unlock()
655+
e.startupMutex.Unlock()
656656
return e.serve()
657657
}
658658

659659
// StartTLS starts an HTTPS server.
660660
// If `certFile` or `keyFile` is `string` the values are treated as file paths.
661661
// If `certFile` or `keyFile` is `[]byte` the values are treated as the certificate or key as-is.
662662
func (e *Echo) StartTLS(address string, certFile, keyFile interface{}) (err error) {
663-
e.startupMu.Lock()
663+
e.startupMutex.Lock()
664664
var cert []byte
665665
if cert, err = filepathOrContent(certFile); err != nil {
666-
e.startupMu.Unlock()
666+
e.startupMutex.Unlock()
667667
return
668668
}
669669

670670
var key []byte
671671
if key, err = filepathOrContent(keyFile); err != nil {
672-
e.startupMu.Unlock()
672+
e.startupMutex.Unlock()
673673
return
674674
}
675675

676676
s := e.TLSServer
677677
s.TLSConfig = new(tls.Config)
678678
s.TLSConfig.Certificates = make([]tls.Certificate, 1)
679679
if s.TLSConfig.Certificates[0], err = tls.X509KeyPair(cert, key); err != nil {
680-
e.startupMu.Unlock()
680+
e.startupMutex.Unlock()
681681
return
682682
}
683683

684684
e.configureTLS(address)
685685
if err := e.configureServer(s); err != nil {
686-
e.startupMu.Unlock()
686+
e.startupMutex.Unlock()
687687
return err
688688
}
689-
e.startupMu.Unlock()
689+
e.startupMutex.Unlock()
690690
return s.Serve(e.TLSListener)
691691
}
692692

@@ -703,18 +703,18 @@ func filepathOrContent(fileOrContent interface{}) (content []byte, err error) {
703703

704704
// StartAutoTLS starts an HTTPS server using certificates automatically installed from https://letsencrypt.org.
705705
func (e *Echo) StartAutoTLS(address string) error {
706-
e.startupMu.Lock()
706+
e.startupMutex.Lock()
707707
s := e.TLSServer
708708
s.TLSConfig = new(tls.Config)
709709
s.TLSConfig.GetCertificate = e.AutoTLSManager.GetCertificate
710710
s.TLSConfig.NextProtos = append(s.TLSConfig.NextProtos, acme.ALPNProto)
711711

712712
e.configureTLS(address)
713713
if err := e.configureServer(s); err != nil {
714-
e.startupMu.Unlock()
714+
e.startupMutex.Unlock()
715715
return err
716716
}
717-
e.startupMu.Unlock()
717+
e.startupMutex.Unlock()
718718
return s.Serve(e.TLSListener)
719719
}
720720

@@ -728,12 +728,12 @@ func (e *Echo) configureTLS(address string) {
728728

729729
// StartServer starts a custom http server.
730730
func (e *Echo) StartServer(s *http.Server) (err error) {
731-
e.startupMu.Lock()
731+
e.startupMutex.Lock()
732732
if err := e.configureServer(s); err != nil {
733-
e.startupMu.Unlock()
733+
e.startupMutex.Unlock()
734734
return err
735735
}
736-
e.startupMu.Unlock()
736+
e.startupMutex.Unlock()
737737
return e.serve()
738738
}
739739

@@ -784,8 +784,8 @@ func (e *Echo) serve() error {
784784

785785
// ListenerAddr returns net.Addr for Listener
786786
func (e *Echo) ListenerAddr() net.Addr {
787-
e.startupMu.RLock()
788-
defer e.startupMu.RUnlock()
787+
e.startupMutex.RLock()
788+
defer e.startupMutex.RUnlock()
789789
if e.Listener == nil {
790790
return nil
791791
}
@@ -794,8 +794,8 @@ func (e *Echo) ListenerAddr() net.Addr {
794794

795795
// TLSListenerAddr returns net.Addr for TLSListener
796796
func (e *Echo) TLSListenerAddr() net.Addr {
797-
e.startupMu.RLock()
798-
defer e.startupMu.RUnlock()
797+
e.startupMutex.RLock()
798+
defer e.startupMutex.RUnlock()
799799
if e.TLSListener == nil {
800800
return nil
801801
}
@@ -804,7 +804,7 @@ func (e *Echo) TLSListenerAddr() net.Addr {
804804

805805
// StartH2CServer starts a custom http/2 server with h2c (HTTP/2 Cleartext).
806806
func (e *Echo) StartH2CServer(address string, h2s *http2.Server) (err error) {
807-
e.startupMu.Lock()
807+
e.startupMutex.Lock()
808808
// Setup
809809
s := e.Server
810810
s.Addr = address
@@ -822,22 +822,22 @@ func (e *Echo) StartH2CServer(address string, h2s *http2.Server) (err error) {
822822
if e.Listener == nil {
823823
e.Listener, err = newListener(s.Addr, e.ListenerNetwork)
824824
if err != nil {
825-
e.startupMu.Unlock()
825+
e.startupMutex.Unlock()
826826
return err
827827
}
828828
}
829829
if !e.HidePort {
830830
e.colorer.Printf("⇨ http server started on %s\n", e.colorer.Green(e.Listener.Addr()))
831831
}
832-
e.startupMu.Unlock()
832+
e.startupMutex.Unlock()
833833
return s.Serve(e.Listener)
834834
}
835835

836836
// Close immediately stops the server.
837837
// It internally calls `http.Server#Close()`.
838838
func (e *Echo) Close() error {
839-
e.startupMu.Lock()
840-
defer e.startupMu.Unlock()
839+
e.startupMutex.Lock()
840+
defer e.startupMutex.Unlock()
841841
if err := e.TLSServer.Close(); err != nil {
842842
return err
843843
}
@@ -847,8 +847,8 @@ func (e *Echo) Close() error {
847847
// Shutdown stops the server gracefully.
848848
// It internally calls `http.Server#Shutdown()`.
849849
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()
852852
if err := e.TLSServer.Shutdown(ctx); err != nil {
853853
return err
854854
}

0 commit comments

Comments
 (0)