summary refs log tree commit diff stats
path: root/svc
diff options
context:
space:
mode:
Diffstat (limited to 'svc')
-rw-r--r--svc/svc.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/svc/svc.go b/svc/svc.go
index a7786d9..d8b4128 100644
--- a/svc/svc.go
+++ b/svc/svc.go
@@ -1,6 +1,7 @@
 package svc // import "github.com/getwtxt/getwtxt/svc"
 
 import (
+	"crypto/tls"
 	"fmt"
 	"log"
 	"net/http"
@@ -34,12 +35,21 @@ func Start() {
 	confObj.Mu.RUnlock()
 
 	server := newServer(portnum, index)
-	log.Printf("*** Listening on %v\n", portnum)
-	log.Printf("*** getwtxt %v Startup finished at %v, took %v\n\n", Vers, time.Now().Format(time.RFC3339), time.Since(before))
 
 	if TLS {
-		errLog("", server.ListenAndServeTLS(TLSCert, TLSKey))
+		cert, err := tls.LoadX509KeyPair(TLSCert, TLSKey)
+		errFatal("", err)
+
+		cfg := &tls.Config{Certificates: []tls.Certificate{cert}}
+		lstnr, err := tls.Listen("tcp", portnum, cfg)
+		errFatal("", err)
+
+		server.TLSConfig = cfg
+		startAnnounce(portnum, before)
+		errLog("", server.ServeTLS(lstnr, "", ""))
+
 	} else {
+		startAnnounce(portnum, before)
 		errLog("", server.ListenAndServe())
 	}
 
@@ -50,6 +60,11 @@ func Start() {
 	close(closeLog)
 }
 
+func startAnnounce(portnum string, before time.Time) {
+	log.Printf("*** Listening on %v\n", portnum)
+	log.Printf("*** getwtxt %v Startup finished at %v, took %v\n\n", Vers, time.Now().Format(time.RFC3339), time.Since(before))
+}
+
 func newServer(port string, index *mux.Router) *http.Server {
 	// handlers.CompressHandler gzips all responses.
 	// ipMiddleware passes the request IP along.