-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
g4ze
committed
Jun 26, 2024
1 parent
9adfc30
commit 045792b
Showing
6 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
AWS_ACCESS_KEY_ID= | ||
AWS_SECRET_ACCESS_KEY= | ||
AWS_REGION= | ||
ECS_VPC= | ||
SUBNET1= | ||
SUBNET2= | ||
SUBNET3= | ||
JWT_SECRET= | ||
HOST_URL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package handlers | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/g4ze/byoc/pkg/database/db" | ||
"github.com/gin-gonic/gin" | ||
"github.com/joho/godotenv" | ||
) | ||
|
||
// health should check the health of the service | ||
// database activity, tables | ||
// aws keys and connection | ||
// other related env variables | ||
// and return errors accordingly | ||
func Health(c *gin.Context) { | ||
err := godotenv.Load() | ||
if err != nil { | ||
c.JSON(500, gin.H{"error": "Error loading .env file", "message": err.Error()}) | ||
return | ||
} | ||
AWS_REGION := os.Getenv("AWS_REGION") | ||
AWS_ACCESS_KEY_ID := os.Getenv("AWS_ACCESS_KEY_ID") | ||
AWS_SECRET_ACCESS_KEY := os.Getenv("AWS_SECRET_ACCESS_KEY") | ||
ECS_VPC := os.Getenv("ECS_VPC") | ||
SUBNET1 := os.Getenv("SUBNET1") | ||
SUBNET2 := os.Getenv("SUBNET2") | ||
SUBNET3 := os.Getenv("SUBNET3") | ||
JWT_SECRET := os.Getenv("JWT_SECRET") | ||
if AWS_REGION == "" || AWS_ACCESS_KEY_ID == "" || AWS_SECRET_ACCESS_KEY == "" || ECS_VPC == "" || SUBNET1 == "" || SUBNET2 == "" || SUBNET3 == "" || JWT_SECRET == "" { | ||
c.JSON(500, gin.H{"error": "Missing env variables"}) | ||
} | ||
|
||
// databse pinging | ||
client := db.NewClient() | ||
if err := client.Prisma.Connect(); err != nil { | ||
c.JSON(500, gin.H{"error": "Error connecting to database", "message": err.Error()}) | ||
return | ||
} | ||
func() { | ||
if err := client.Prisma.Disconnect(); err != nil { | ||
c.JSON(500, gin.H{"error": "Error disconnecting from database", "message": err.Error()}) | ||
} | ||
}() | ||
c.JSON(200, gin.H{"message": "Service is healthy"}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters