From db71e875dc27d65c0d705cedb0145b093e0c0684 Mon Sep 17 00:00:00 2001 From: wRhlH Date: Sat, 17 Jun 2023 14:39:50 +0800 Subject: [PATCH] optimize the mysql connection state check logic --- backend/main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/main.go b/backend/main.go index 87d916f..4a0dccf 100644 --- a/backend/main.go +++ b/backend/main.go @@ -49,6 +49,12 @@ func main() { panic(err.Error()) } + // check the connection + err = db.Ping() + if err != nil { + panic(err.Error()) + } + defer db.Close() fmt.Println("Successfully connected to MySQL database")