Skip to content

Commit

Permalink
Added healthcheck func
Browse files Browse the repository at this point in the history
  • Loading branch information
scheibling committed Feb 3, 2024
1 parent c534744 commit d850c79
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"log"
"net/http"
"os"
"strings"
"time"
Expand Down Expand Up @@ -202,16 +203,25 @@ func Listen(s *smtp.Server) {
log.Println("Starting server at", s.Addr)
if err := s.ListenAndServe(); err != nil {
log.Fatal(err)
panic(err)
}
}

func ListemSmtps(tlss *smtp.Server) {
log.Println("Starting TLS server at ", tlss.Addr)
if err := tlss.ListenAndServeTLS(); err != nil {
log.Fatal(err)
panic(err)
}
}

func ListenHealthcheck() {
http.ListenAndServe(":8080", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("OK"))
})) // nolint:errcheck
}

func main() {
// Create config
config = &Config{}
Expand Down Expand Up @@ -244,6 +254,10 @@ func main() {
config.Server.TLSKey,
)

if err != nil {
log.Fatal(err)
}

certInfo, err := x509.ParseCertificate(tlsCert.Certificate[0])

if err != nil {
Expand Down Expand Up @@ -316,5 +330,7 @@ func main() {
go ListemSmtps(smtpss)
}

Listen(smtps)
go Listen(smtps)

ListenHealthcheck()
}

0 comments on commit d850c79

Please sign in to comment.