47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"log/slog"
|
|
"orbits-server/internal/server/api"
|
|
"orbits-server/internal/server/bootstrap"
|
|
"orbits-server/internal/server/database"
|
|
"orbits-server/internal/shared/utility"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
// grab the environment variables from the runtime environment
|
|
// unfortunately since its before we configure the loglevel, we cannot use slog logging in those functions
|
|
env := bootstrap.LoadConfig()
|
|
// configure the logger so we have nice json
|
|
level := utility.ParseSlogLevel(env.LogLevel) // defaults to Info
|
|
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
|
Level: &level,
|
|
}))
|
|
slog.SetDefault(logger)
|
|
|
|
// print our running environment variable set
|
|
slog.Debug("displaying environment variables", "environment", env)
|
|
|
|
// initiating the database connection for which we safe things
|
|
slog.Info("kicking off database connection")
|
|
db, err := database.KickoffDatabase(env.DataDirectory)
|
|
if err != nil {
|
|
slog.Error("failed to initiate a database connection", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// kick off the watchdog depending on the environment variables
|
|
if env.Watchdog {
|
|
slog.Info("kicking off database watchdog", "watchdog_interval", env.WatchdogInterval)
|
|
database.KickoffDatabaseWatchdog(env, db)
|
|
} else {
|
|
slog.Info("skipping database watchdog", "watchdog_enabled", env.Watchdog)
|
|
}
|
|
|
|
// TO DO make gin log as json
|
|
// get ready to kick off the http api with Vue frontend
|
|
slog.Info("kicking off http api backend")
|
|
api.KickoffApi(logger, env, db)
|
|
}
|