Merge pull request #118 from Erope/pull

WebSocket增加Ping包 & Actions构建镜像时用户名转为小写

Co-authored-by: Erope <44471469+Erope@users.noreply.github.com>
This commit is contained in:
naiba 2021-04-04 23:12:10 +08:00 committed by GitHub
commit 31370292ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -22,6 +22,8 @@ jobs:
- name: Build and push dasbboard image - name: Build and push dasbboard image
run: | run: |
go env
go test -v ./... go test -v ./...
docker build -t ghcr.io/${{ github.repository_owner }}/nezha-dashboard -f Dockerfile . IMAGE_NAME=$(echo "ghcr.io/${{ github.repository_owner }}/nezha-dashboard" | tr '[:upper:]' '[:lower:]')
docker push ghcr.io/${{ github.repository_owner }}/nezha-dashboard docker build -t $IMAGE_NAME -f Dockerfile .
docker push $IMAGE_NAME

View File

@ -185,6 +185,7 @@ func (cp *commonPage) ws(c *gin.Context) {
return return
} }
defer conn.Close() defer conn.Close()
count := 0
for { for {
dao.SortedServerLock.RLock() dao.SortedServerLock.RLock()
err = conn.WriteJSON(dao.SortedServerList) err = conn.WriteJSON(dao.SortedServerList)
@ -192,6 +193,13 @@ func (cp *commonPage) ws(c *gin.Context) {
if err != nil { if err != nil {
break break
} }
count += 1
if count%4 == 0 {
err = conn.WriteMessage(websocket.PingMessage, []byte{})
if err != nil {
break
}
}
time.Sleep(time.Second * 2) time.Sleep(time.Second * 2)
} }
} }