mirror of
https://github.com/trafficlunar/api.git
synced 2026-08-12 12:29:39 +00:00
feat: data store
This commit is contained in:
parent
4f8ee6cf9c
commit
19bdd27de1
8 changed files with 123 additions and 53 deletions
21
main.go
21
main.go
|
|
@ -3,11 +3,14 @@ package main
|
|||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/lmittmann/tint"
|
||||
|
||||
"api/internal/server"
|
||||
"api/internal/storage"
|
||||
"api/internal/worker"
|
||||
)
|
||||
|
||||
|
|
@ -20,6 +23,24 @@ func main() {
|
|||
slog.Warn("No .env file was found; using environment variables.", slog.Any("error", err))
|
||||
}
|
||||
|
||||
storage.InitDataStore()
|
||||
go worker.StartWorkers()
|
||||
|
||||
// Shutdown-chan~~
|
||||
shutdownChan := make(chan os.Signal, 1)
|
||||
signal.Notify(shutdownChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
<-shutdownChan
|
||||
|
||||
if err := storage.GlobalDataStore.Save(); err != nil {
|
||||
slog.Error("Error saving data store on shutdown", slog.Any("error", err))
|
||||
} else {
|
||||
slog.Info("Data store saved successfully on shutdown")
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
}()
|
||||
|
||||
server.NewRouter()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue