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"
|
2024-09-07 12:10:48 +02:00
|
|
|
"strconv"
|
2024-08-28 07:21:02 +02:00
|
|
|
"syscall"
|
2024-09-18 07:09:25 +02:00
|
|
|
|
2024-09-18 07:29:48 +02:00
|
|
|
"go-mod.ewintr.nl/planner/sync/planner"
|
2024-08-21 16:35:44 +02:00
|
|
|
)
|
|
|
|
|
2024-07-26 13:37:21 +02:00
|
|
|
func main() {
|
2024-09-09 16:36:03 +02:00
|
|
|
dbPath := os.Getenv("PLANNER_DB_PATH")
|
|
|
|
if dbPath == "" {
|
|
|
|
fmt.Println("PLANNER_DB_PATH is empty")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2024-09-07 12:10:48 +02:00
|
|
|
port, err := strconv.Atoi(os.Getenv("PLANNER_PORT"))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("PLANNER_PORT env is not an integer")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
apiKey := os.Getenv("PLANNER_API_KEY")
|
|
|
|
if apiKey == "" {
|
|
|
|
fmt.Println("PLANNER_API_KEY is empty")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2024-09-18 07:29:48 +02:00
|
|
|
repo, err := planner.NewSqlite(dbPath)
|
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-12 07:19:30 +02:00
|
|
|
"dbPath": dbPath,
|
|
|
|
"port": fmt.Sprintf("%d", port),
|
|
|
|
"apiKey": "***",
|
2024-09-10 14:30:05 +02:00
|
|
|
})
|
2024-08-21 16:35:44 +02:00
|
|
|
|
2024-09-10 14:01:13 +02:00
|
|
|
address := fmt.Sprintf(":%d", port)
|
2024-09-18 07:29:48 +02:00
|
|
|
srv := planner.NewServer(repo, apiKey, logger)
|
2024-09-12 07:19:30 +02:00
|
|
|
go http.ListenAndServe(address, 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
|
|
|
}
|