fix the bug of database cannot auto reconnect.
This commit is contained in:
parent
0f7481f041
commit
45b0d2f388
2
Makefile
2
Makefile
|
|
@ -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
|
||||||
|
|
|
||||||
1
main.go
1
main.go
|
|
@ -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")
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue