feat(server): support TLS

* Added https support. Will revert to http if either cert or key are empty strings.

* Update server/server.go

Co-authored-by: Senan Kelly <senan@senan.xyz>

* Fixed lint issues.

Co-authored-by: Senan Kelly <senan@senan.xyz>
This commit is contained in:
brian-doherty
2022-03-14 18:34:52 -05:00
committed by sentriz
parent 5155dee2e8
commit 59c404749f
3 changed files with 20 additions and 13 deletions

View File

@@ -264,7 +264,7 @@ type (
FuncInterrupt func(error)
)
func (s *Server) StartHTTP(listenAddr string) (FuncExecute, FuncInterrupt) {
func (s *Server) StartHTTP(listenAddr string, tlsCert string, tlsKey string) (FuncExecute, FuncInterrupt) {
list := &http.Server{
Addr: listenAddr,
Handler: s.router,
@@ -274,6 +274,9 @@ func (s *Server) StartHTTP(listenAddr string) (FuncExecute, FuncInterrupt) {
}
return func() error {
log.Print("starting job 'http'\n")
if tlsCert != "" && tlsKey != "" {
return list.ListenAndServeTLS(tlsCert, tlsKey)
}
return list.ListenAndServe()
}, func(_ error) {
// stop job