Skip to content

Commit 23d46ad

Browse files
committed
fix dish.StreamerStats exporting
1 parent 2864f59 commit 23d46ad

File tree

5 files changed

+21
-29
lines changed

5 files changed

+21
-29
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
APP_NAME=swis-api
66
APP_ROOT=/opt/${APP_NAME}
7-
APP_VERSION=5.17.8
7+
APP_VERSION=5.17.9
88

99

1010
#

api/swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"name": "MIT",
1414
"url": "https://github.com/vxn-dev/swis-api/blob/master/LICENSE"
1515
},
16-
"version": "5.17.8"
16+
"version": "5.17.9"
1717
},
1818
"host": "swis-api-run-prod:8050",
1919
"basePath": "/",

cmd/swis-api/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @title swis-api (swapi) v5
2-
// @version 5.17.8
2+
// @version 5.17.9
33
// @description sakalWeb Information System v5 RESTful API documentation
44
// @termsOfService http://swagger.io/terms/
55

@@ -79,6 +79,7 @@ func main() {
7979
// @Description Simple ping-pong route
8080
// @Success 200
8181
// @Router /ping [get]
82+
// @Router /ping [head]
8283
// Very simple LE support --- https://github.com/gin-gonic/gin#support-lets-encrypt.
8384
router.GET("/ping", func(c *gin.Context) {
8485
c.String(http.StatusOK, "pong")

pkg/dish/controllers.go

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -748,50 +748,36 @@ func GetIncidentListBySocketID(ctx *gin.Context) {
748748
// @Router /dish/streamer/stats [get]
749749
func GetStreamerStats(ctx *gin.Context) {
750750
var counter int
751-
var key string = "stats"
751+
var exportedStats = map[string]StreamerStats{}
752752

753753
if CacheStreamer == nil {
754754
ctx.IndentedJSON(http.StatusInternalServerError, gin.H{
755755
"code": http.StatusInternalServerError,
756756
"count": counter,
757757
"package": pkgName,
758758
"message": "cannot access streamer cache",
759-
"key": key,
760759
})
761760
return
762761
}
763762

764-
rawStat, ok := CacheSockets.Get(key)
765-
if !ok {
766-
ctx.IndentedJSON(http.StatusNotFound, gin.H{
767-
"code": http.StatusNotFound,
768-
"count": counter,
769-
"package": pkgName,
770-
"message": "no streamer statistics",
771-
"key": key,
772-
})
773-
return
774-
}
763+
rawStats, counter := CacheStreamer.GetAll()
775764

776-
stat, ok := rawStat.(StreamerStats)
777-
if !ok {
778-
ctx.IndentedJSON(http.StatusInternalServerError, gin.H{
779-
"code": http.StatusInternalServerError,
780-
"count": counter,
781-
"package": pkgName,
782-
"message": "could not assert type dish.StreamerStats",
783-
"key": key,
784-
})
785-
return
765+
// loop over string-map of interface{}
766+
for key, rawStat := range rawStats {
767+
stat, ok := rawStat.(StreamerStats)
768+
if !ok {
769+
continue
770+
}
771+
772+
exportedStats[key] = stat
786773
}
787774

788-
counter++
789775
ctx.IndentedJSON(http.StatusOK, gin.H{
790776
"code": http.StatusOK,
791777
"count": counter,
792-
"item": stat,
778+
"items": exportedStats,
793779
"message": "ok, dumping streamer statistics",
794-
"key": key,
780+
"package": pkgName,
795781
})
796782
return
797783
}

pkg/dish/stream.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ func NewDispatcher() (stream *Stream) {
1818
go stream.listen()
1919
go stream.heartbeat()
2020

21+
// Init stats
22+
if CacheStreamer != nil {
23+
CacheStreamer.Set("stats", StreamerStats{ClientCount: 0})
24+
}
25+
2126
return stream
2227
}
2328

0 commit comments

Comments
 (0)