2024-02-10 15:17:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-02-25 20:13:04 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2024-02-10 15:17:34 +00:00
|
|
|
|
|
|
|
"github.com/pikami/cosmium/api"
|
2024-02-13 23:47:51 +00:00
|
|
|
"github.com/pikami/cosmium/api/config"
|
2024-02-14 18:46:40 +00:00
|
|
|
"github.com/pikami/cosmium/internal/repositories"
|
2024-02-10 15:17:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-02-13 23:47:51 +00:00
|
|
|
config.ParseFlags()
|
2024-02-10 15:17:34 +00:00
|
|
|
|
2024-02-25 20:13:04 +00:00
|
|
|
if config.Config.InitialDataFilePath != "" {
|
|
|
|
repositories.LoadStateFS(config.Config.InitialDataFilePath)
|
2024-02-14 18:46:40 +00:00
|
|
|
}
|
|
|
|
|
2024-02-10 15:17:34 +00:00
|
|
|
router := api.CreateRouter()
|
2024-02-25 20:13:04 +00:00
|
|
|
if config.Config.TLS_CertificatePath == "" ||
|
|
|
|
config.Config.TLS_CertificateKey == "" {
|
|
|
|
go router.Run(fmt.Sprintf(":%d", config.Config.Port))
|
|
|
|
} else {
|
|
|
|
go router.RunTLS(
|
|
|
|
fmt.Sprintf(":%d", config.Config.Port),
|
|
|
|
config.Config.TLS_CertificatePath,
|
|
|
|
config.Config.TLS_CertificateKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
waitForExit()
|
|
|
|
}
|
|
|
|
|
|
|
|
func waitForExit() {
|
|
|
|
sigs := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
|
|
|
|
// Block until a exit signal is received
|
|
|
|
<-sigs
|
|
|
|
|
|
|
|
if config.Config.PersistDataFilePath != "" {
|
|
|
|
repositories.SaveStateFS(config.Config.PersistDataFilePath)
|
|
|
|
}
|
2024-02-10 15:17:34 +00:00
|
|
|
}
|