Skip to content

Commit

Permalink
add tls configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ross96D committed Aug 27, 2024
1 parent f932e08 commit 7e632f4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,28 @@ import (
)

type Server struct {
router *chi.Mux
router *chi.Mux
keyPath string
certPath string
}

func New() *Server {
func New(keyPath, certPath string) *Server {
s := new(Server)
s.certPath = certPath
s.keyPath = keyPath
s.router = chi.NewMux()
s.setHandlers()
return s
}

func (s *Server) Start() error {
log.Info().Msg("starting server on " + ":" + strconv.Itoa(int(share.Config().Port)))
return http.ListenAndServe(":"+strconv.Itoa(int(share.Config().Port)), s.router)
portStr := ":" + strconv.Itoa(int(share.Config().Port))
if s.certPath != "" && s.keyPath != "" {
return http.ListenAndServeTLS(portStr, s.certPath, s.keyPath, s.router)
} else {
return http.ListenAndServe(portStr, s.router)
}
}

func (s *Server) setHandlers() {
Expand Down

0 comments on commit 7e632f4

Please sign in to comment.