Implement TLS support: update configuration for TLS, modify server to handle HTTPS, and enhance logging for request handling

This commit is contained in:
alex
2025-06-24 22:15:37 +03:00
parent 973c060e5f
commit ef1efdd585
8 changed files with 75 additions and 54 deletions

View File

@@ -39,11 +39,21 @@ func main() {
Config: cfg,
}, serverv1)
r := chi.NewRouter()
r.Route("/{ver}/com", func(r chi.Router) {
r.Route("/api/{ver}/com", func(r chi.Router) {
r.Get("/", s.HandleList)
r.Get("/{cmd}", s.Handle)
})
r.NotFound(serverv1.ErrNotFound)
if cfg.TlsEnabled == "true" {
log.Info("Server started with TLS", slog.String("address", cfg.Address))
err := http.ListenAndServeTLS(cfg.Address, cfg.CertFile, cfg.KeyFile, r)
if err != nil {
log.Error("Failed to start HTTPS server", slog.String("error", err.Error()))
}
}
log.Info("Server started", slog.String("address", cfg.Address))
http.ListenAndServe(cfg.Address, r)
err := http.ListenAndServe(cfg.Address, r)
if err != nil {
log.Error("Failed to start HTTP server", slog.String("error", err.Error()))
}
}