MCPcopy
hub / github.com/tinode/chat / serveStatus

Function serveStatus

server/http.go:419–485  ·  view source on GitHub ↗
(wrt http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

417}
418
419func serveStatus(wrt http.ResponseWriter, req *http.Request) {
420 wrt.Header().Set("Content-Type", "application/json")
421
422 result := &debugDump{
423 Version: currentVersion,
424 Build: buildstamp,
425 Timestamp: types.TimeNow(),
426 Sessions: make([]debugSession, 0, len(globals.sessionStore.sessCache)),
427 Topics: make([]debugTopic, 0, 10),
428 UserCache: make([]debugCachedUser, 0, 10),
429 }
430 // Sessions.
431 globals.sessionStore.Range(func(sid string, s *Session) bool {
432 keys := make([]string, 0, len(s.subs))
433 for tn := range s.subs {
434 keys = append(keys, tn)
435 }
436 sort.Strings(keys)
437 var clnode string
438 if s.clnode != nil {
439 clnode = s.clnode.name
440 }
441 result.Sessions = append(result.Sessions, debugSession{
442 RemoteAddr: s.remoteAddr,
443 Ua: s.userAgent,
444 Uid: s.uid.String(),
445 Sid: sid,
446 Clnode: clnode,
447 Subs: keys,
448 })
449 return true
450 })
451 // Topics.
452 globals.hub.topics.Range(func(_, t any) bool {
453 topic := t.(*Topic)
454 psd := make([]string, 0, len(topic.sessions))
455 for s := range topic.sessions {
456 psd = append(psd, s.sid)
457 }
458 pud := make([]string, 0, len(topic.perUser))
459 for uid := range topic.perUser {
460 pud = append(pud, uid.String())
461 }
462 ps := make([]string, 0, len(topic.perSubs))
463 for key := range topic.perSubs {
464 ps = append(ps, key)
465 }
466 result.Topics = append(result.Topics, debugTopic{
467 Topic: topic.name,
468 Xorig: topic.xoriginal,
469 IsProxy: topic.isProxy,
470 PerUser: pud,
471 PerSubs: ps,
472 Sessions: psd,
473 })
474 return true
475 })
476 for k, v := range usersCache {

Callers

nothing calls this directly

Calls 4

TimeNowFunction · 0.92
RangeMethod · 0.80
UserIdMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…