From 663c95788013af7e7ccf874e93a3160db94a27f1 Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Sat, 14 Jun 2025 21:34:37 -0400 Subject: [PATCH] .env files don't appear to work with air --- .air.toml | 3 --- .env.template | 6 +++--- .gitignore | 1 + cmd/api/main.go | 9 +++++---- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.air.toml b/.air.toml index f9d6ad7..8491d61 100644 --- a/.air.toml +++ b/.air.toml @@ -2,9 +2,6 @@ root = "." testdata_dir = "testdata" tmp_dir = "tmp" -[env] -file = ".env" - [build] args_bin = ["-log-level=DEBUG"] bin = "./tmp/main" diff --git a/.env.template b/.env.template index 8538c2e..ea9150f 100644 --- a/.env.template +++ b/.env.template @@ -1,4 +1,4 @@ -export PULLEY_DATABASE_URI=postgres://pulley:passwd@localhost:5434/pulley -export PULLEY_PORT=5002 -export PULLEY_LOG_LEVEL="debug" +PULLEY_DATABASE_URI=postgres://pulley:passwd@localhost:5434/pulley +PULLEY_PORT=5002 +PULLEY_LOG_LEVEL="debug" diff --git a/.gitignore b/.gitignore index 2f3b2bc..4516cd5 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ go.work tmp/ .pg_data/ .env +.local.profile diff --git a/cmd/api/main.go b/cmd/api/main.go index 9b8f581..e5f45a3 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -97,9 +97,8 @@ func run(ctx context.Context, w io.Writer, args []string) error { go func() { if err := srv.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) { - slog.Error(err.Error()) - os.Exit(1) - slog.Info("Stopped serving connections") + slog.Error("Error encounterd by webserver in listen loop", "error", err.Error()) + cancel() } }() @@ -110,9 +109,11 @@ func run(ctx context.Context, w io.Writer, args []string) error { // signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) // Block until signal is received //<-sigChan - + slog.Info("Listening for shutdown...") <-appCtx.Done() + slog.Info("Shutdown intitiated") + // We don't want to inherit from appCtx because it has already been canceled at this point shutdownCtx, shutdownRelease := context.WithTimeout(context.Background(), 10*time.Second) defer shutdownRelease()