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

Function demonstrateSessionListing

examples/session/main.go:222–258  ·  view source on GitHub ↗

演示会话列表

(ctx context.Context, service *session.InMemoryService)

Source from the content-addressed store, hash-verified

220
221// 演示会话列表
222func demonstrateSessionListing(ctx context.Context, service *session.InMemoryService) {
223 fmt.Println("📚 Session Listing Demo")
224 fmt.Println("=======================")
225
226 // 创建多个会话
227 for i := 1; i <= 3; i++ {
228 _, _ = service.Create(ctx, &session.CreateRequest{
229 AppName: "my-app",
230 UserID: "user-123",
231 AgentID: fmt.Sprintf("agent-%03d", i),
232 })
233 }
234
235 // 列出会话
236 sessions, err := service.List(ctx, &session.ListRequest{
237 AppName: "my-app",
238 UserID: "user-123",
239 Limit: 10,
240 })
241 if err != nil {
242 log.Printf("Error listing sessions: %v", err)
243 return
244 }
245
246 fmt.Printf("\n📊 Total sessions for user-123: %d\n", len(sessions))
247 for i, sess := range sessions {
248 s := *sess
249 fmt.Printf(" %d. %s (Agent: %s, Updated: %s)\n",
250 i+1,
251 s.ID(),
252 s.AgentID(),
253 s.LastUpdateTime().Format("15:04:05"),
254 )
255 }
256
257 fmt.Println()
258}
259
260// 辅助函数:获取状态作用域
261func getScope(key string) string {

Callers 1

mainFunction · 0.85

Calls 6

PrintfMethod · 0.80
CreateMethod · 0.65
ListMethod · 0.65
IDMethod · 0.65
AgentIDMethod · 0.65
LastUpdateTimeMethod · 0.65

Tested by

no test coverage detected