Skip to content

Commit d850c79

Browse files
committed
Added healthcheck func
1 parent c534744 commit d850c79

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

main.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"io"
1111
"log"
12+
"net/http"
1213
"os"
1314
"strings"
1415
"time"
@@ -202,16 +203,25 @@ func Listen(s *smtp.Server) {
202203
log.Println("Starting server at", s.Addr)
203204
if err := s.ListenAndServe(); err != nil {
204205
log.Fatal(err)
206+
panic(err)
205207
}
206208
}
207209

208210
func ListemSmtps(tlss *smtp.Server) {
209211
log.Println("Starting TLS server at ", tlss.Addr)
210212
if err := tlss.ListenAndServeTLS(); err != nil {
211213
log.Fatal(err)
214+
panic(err)
212215
}
213216
}
214217

218+
func ListenHealthcheck() {
219+
http.ListenAndServe(":8080", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
220+
w.WriteHeader(200)
221+
w.Write([]byte("OK"))
222+
})) // nolint:errcheck
223+
}
224+
215225
func main() {
216226
// Create config
217227
config = &Config{}
@@ -244,6 +254,10 @@ func main() {
244254
config.Server.TLSKey,
245255
)
246256

257+
if err != nil {
258+
log.Fatal(err)
259+
}
260+
247261
certInfo, err := x509.ParseCertificate(tlsCert.Certificate[0])
248262

249263
if err != nil {
@@ -316,5 +330,7 @@ func main() {
316330
go ListemSmtps(smtpss)
317331
}
318332

319-
Listen(smtps)
333+
go Listen(smtps)
334+
335+
ListenHealthcheck()
320336
}

0 commit comments

Comments
 (0)