Files
chatservice_concept/main.go
2025-05-25 13:44:51 -04:00

44 lines
953 B
Go

package main
import (
"log/slog"
"os"
"git.dubyatp.xyz/chat-api-server/api"
"git.dubyatp.xyz/chat-api-server/log"
"github.com/joho/godotenv"
)
func checkEnvVars(keys []string) (bool, []string) {
var missing []string
for _, key := range keys {
if _, ok := os.LookupEnv(key); !ok {
missing = append(missing, key)
}
}
return len(missing) == 0, missing
}
func main() {
log.Logger() // initialize logger
requiredEnvVars := []string{"SCYLLA_CLUSTER", "SCYLLA_KEYSPACE", "JWT_SECRET", "ALLOWED_ORIGINS"}
// Initialize dotenv file
err := godotenv.Load()
if err != nil {
slog.Info("No .env file loaded, will try OS environment variables")
}
// Check if environment variables were defined by the OS before erroring out
exists, missingVars := checkEnvVars(requiredEnvVars)
if !exists {
slog.Error("Missing environment variables", "missing", missingVars)
os.Exit(1)
}
slog.Info("Starting the API Server...")
api.Start()
}