MCPcopy Create free account
hub / github.com/astercloud/aster / List

Method List

server/handlers/session.go:88–127  ·  view source on GitHub ↗

List lists all sessions

(c *gin.Context)

Source from the content-addressed store, hash-verified

86
87// List lists all sessions
88func (h *SessionHandler) List(c *gin.Context) {
89 ctx := c.Request.Context()
90 agentID := c.Query("agent_id")
91 status := c.Query("status")
92
93 records, err := (*h.store).List(ctx, "sessions")
94 if err != nil {
95 c.JSON(http.StatusInternalServerError, gin.H{
96 "success": false,
97 "error": gin.H{
98 "code": "internal_error",
99 "message": "Failed to list sessions: " + err.Error(),
100 },
101 })
102 return
103 }
104
105 sessions := make([]*SessionRecord, 0)
106 for _, record := range records {
107 var session SessionRecord
108 if err := store.DecodeValue(record, &session); err != nil {
109 continue
110 }
111
112 // 过滤
113 if agentID != "" && session.AgentID != agentID {
114 continue
115 }
116 if status != "" && session.Status != status {
117 continue
118 }
119
120 sessions = append(sessions, &session)
121 }
122
123 c.JSON(http.StatusOK, gin.H{
124 "success": true,
125 "data": sessions,
126 })
127}
128
129// Get retrieves a single session
130func (h *SessionHandler) Get(c *gin.Context) {

Callers

nothing calls this directly

Calls 6

DecodeValueFunction · 0.92
JSONMethod · 0.80
ContextMethod · 0.65
QueryMethod · 0.65
ListMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected