@@ -80,30 +80,32 @@ func New(config *ServerConfig, p interfaces.Provider, l hclog.Logger) (*Server,
8080
8181// Start the server and block until complete
8282func (a * Server ) Start () error {
83- // Create TLS listener.
84- a .logger .Info ("HTTPS Listening on " , "address" , a .config .TLSBindAddress , "port" , a .config .TLSBindPort )
85- l , err := net .Listen ("tcp4" , fmt .Sprintf ("%s:%d" , a .config .TLSBindAddress , a .config .TLSBindPort ))
86- if err != nil {
87- return fmt .Errorf ("unable to create TCP listener: %s" , err )
88- }
89-
90- a .httpsListener = l
83+ errChan := make (chan error )
9184
92- a .httpsServer = & http.Server {
93- Handler : a .router ,
94- ReadTimeout : 10 * time .Second ,
95- WriteTimeout : 10 * time .Second ,
96- }
85+ if a .config .TLSBindAddress != "" {
86+ // Create TLS listener.
87+ a .logger .Info ("HTTPS Listening on " , "address" , a .config .TLSBindAddress , "port" , a .config .TLSBindPort )
88+ l , err := net .Listen ("tcp4" , fmt .Sprintf ("%s:%d" , a .config .TLSBindAddress , a .config .TLSBindPort ))
89+ if err != nil {
90+ return fmt .Errorf ("unable to create TCP listener: %s" , err )
91+ }
9792
98- errChan := make ( chan error )
93+ a . httpsListener = l
9994
100- // start the TLS endpoint
101- go func () {
102- err := a .httpsServer .Serve (tls .NewListener (l , a .tlsConfig ))
103- if err != nil && err != http .ErrServerClosed {
104- errChan <- fmt .Errorf ("unable to start TLS server: %s" , err )
95+ a .httpsServer = & http.Server {
96+ Handler : a .router ,
97+ ReadTimeout : 10 * time .Second ,
98+ WriteTimeout : 10 * time .Second ,
10599 }
106- }()
100+
101+ // start the TLS endpoint
102+ go func () {
103+ err := a .httpsServer .Serve (tls .NewListener (l , a .tlsConfig ))
104+ if err != nil && err != http .ErrServerClosed {
105+ errChan <- fmt .Errorf ("unable to start TLS server: %s" , err )
106+ }
107+ }()
108+ }
107109
108110 // if we are listening on plain HTTP start the server
109111 if a .config .HTTPBindAddress != "" {
0 commit comments