fix the bug of database cannot auto reconnect.

This commit is contained in:
w-mj 2023-02-26 11:12:41 +08:00
parent 0f7481f041
commit 45b0d2f388
No known key found for this signature in database
GPG Key ID: 3A2CB5BE2F835897
3 changed files with 4 additions and 1 deletions

View File

@ -1,4 +1,4 @@
IMAGE_TAG ?= docker.educg.net/cg/k8s-manager:v1.1.0 IMAGE_TAG ?= docker.educg.net/cg/k8s-manager:v1.1.1
build: export CGO_ENABLED=0 build: export CGO_ENABLED=0
build: export GOOS=linux build: export GOOS=linux

View File

@ -164,6 +164,7 @@ func Test(c *gin.Context) {
c.Abort() c.Abort()
return return
} }
log.WithField("user name", username).Info("Login success.")
c.SetCookie("Authorization", "Bearer "+token, 0, "", "", false, false) c.SetCookie("Authorization", "Bearer "+token, 0, "", "", false, false)
c.Header("Authorization", "Bearer "+token) c.Header("Authorization", "Bearer "+token)
c.Header("Cache-Control", "no-store") c.Header("Cache-Control", "no-store")

View File

@ -56,6 +56,7 @@ func checkdb(cnt int) *gorm.DB {
if err != nil { if err != nil {
logrus.WithError(err).Errorf("Close error %d.", cnt) logrus.WithError(err).Errorf("Close error %d.", cnt)
} }
instance = nil
ans = nil ans = nil
} }
} }
@ -67,5 +68,6 @@ func DB() *gorm.DB {
if ans != nil { if ans != nil {
return ans return ans
} }
instance = nil
return checkdb(2) return checkdb(2)
} }