planner/sync-service/main.go

38 lines
684 B
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"
2024-09-07 12:10:48 +02:00
"strconv"
2024-08-28 07:21:02 +02:00
"syscall"
2024-08-21 16:35:44 +02:00
)
2024-07-26 13:37:21 +02:00
func main() {
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-08 10:09:54 +02:00
mem := NewMemory()
2024-08-28 07:21:02 +02:00
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
2024-08-21 16:35:44 +02:00
2024-09-08 10:09:54 +02:00
go http.ListenAndServe(fmt.Sprintf(":%d", port), NewServer(mem, apiKey, logger))
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
}