add https

This commit is contained in:
Erik Winter 2024-09-10 14:01:13 +02:00
parent 6fb35315fc
commit cb1af81da7
1 changed files with 9 additions and 2 deletions

View File

@ -26,8 +26,9 @@ func main() {
fmt.Println("PLANNER_API_KEY is empty")
os.Exit(1)
}
crtPath := os.Getenv("PLANNER_CRT_PATH")
keyPath := os.Getenv("PLANNER_KEY_PATH")
//mem := NewMemory()
repo, err := NewSqlite(dbPath)
if err != nil {
fmt.Printf("could not open sqlite db: %s", err.Error())
@ -36,7 +37,13 @@ func main() {
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
go http.ListenAndServe(fmt.Sprintf(":%d", port), NewServer(repo, apiKey, logger))
address := fmt.Sprintf(":%d", port)
srv := NewServer(repo, apiKey, logger)
if crtPath != "" || keyPath != "" {
go http.ListenAndServeTLS(address, crtPath, keyPath, srv)
} else {
go http.ListenAndServe(address, srv)
}
logger.Info("service started")