planner/sync/service/main.go

51 lines
1.1 KiB
Go
Raw Normal View History

2024-07-26 13:37:21 +02:00
package main
2024-08-21 16:35:44 +02:00
import (
2024-09-07 12:10:48 +02:00
"fmt"
2024-08-28 07:21:02 +02:00
"log/slog"
2024-08-21 16:35:44 +02:00
"net/http"
2024-08-28 07:21:02 +02:00
"os"
"os/signal"
"syscall"
2024-08-21 16:35:44 +02:00
)
2024-07-26 13:37:21 +02:00
func main() {
2024-09-18 18:04:27 +02:00
port := os.Getenv("PLANNER_PORT")
2024-09-07 12:10:48 +02:00
apiKey := os.Getenv("PLANNER_API_KEY")
if apiKey == "" {
fmt.Println("PLANNER_API_KEY is empty")
os.Exit(1)
}
2024-09-18 18:04:27 +02:00
dbHost := os.Getenv("PLANNER_DB_HOST")
dbPort := os.Getenv("PLANNER_DB_PORT")
dbName := os.Getenv("PLANNER_DB_NAME")
dbUser := os.Getenv("PLANNER_DB_USER")
dbPassword := os.Getenv("PLANNER_DB_PASSWORD")
repo, err := NewPostgres(dbHost, dbPort, dbName, dbUser, dbPassword)
2024-09-08 11:17:49 +02:00
if err != nil {
fmt.Printf("could not open sqlite db: %s", err.Error())
os.Exit(1)
}
2024-08-28 07:21:02 +02:00
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
2024-09-10 14:30:05 +02:00
logger.Info("configuration", "configuration", map[string]string{
2024-09-18 18:04:27 +02:00
"port": port,
"dbHost": dbHost,
"dbPort": dbPort,
"dbName": dbName,
"dbUser": dbUser,
2024-09-10 14:30:05 +02:00
})
2024-08-21 16:35:44 +02:00
2024-09-18 07:55:14 +02:00
srv := NewServer(repo, apiKey, logger)
2024-09-18 18:04:27 +02:00
go http.ListenAndServe(fmt.Sprintf(":%s", port), srv)
2024-08-21 16:35:44 +02:00
2024-08-28 07:21:02 +02:00
logger.Info("service started")
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
<-c
logger.Info("service stopped")
2024-07-26 13:37:21 +02:00
}