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

Method List

pkg/session/postgres/service.go:164–192  ·  view source on GitHub ↗

List 实现 session.Service 接口

(ctx context.Context, userID string, opts *session.ListOptions)

Source from the content-addressed store, hash-verified

162
163// List 实现 session.Service 接口
164func (s *Service) List(ctx context.Context, userID string, opts *session.ListOptions) ([]*session.SessionData, error) {
165 var models []SessionModel
166 query := s.db.WithContext(ctx).Where("user_id = ?", userID)
167
168 if opts != nil {
169 if opts.AppName != "" {
170 query = query.Where("app_name = ?", opts.AppName)
171 }
172 if opts.Limit > 0 {
173 query = query.Limit(opts.Limit)
174 }
175 if opts.Offset > 0 {
176 query = query.Offset(opts.Offset)
177 }
178 }
179
180 // 按更新时间倒序
181 query = query.Order("updated_at DESC")
182
183 if err := query.Find(&models).Error; err != nil {
184 return nil, fmt.Errorf("list sessions: %w", err)
185 }
186
187 sessions := make([]*session.SessionData, len(models))
188 for i, model := range models {
189 sessions[i] = s.toSession(ctx, &model)
190 }
191 return sessions, nil
192}
193
194// Delete 实现 session.Service 接口
195func (s *Service) Delete(ctx context.Context, sessionID string) error {

Callers

nothing calls this directly

Implementers 2

InMemoryServicepkg/session/inmemory.go
Servicepkg/session/sqlite/store.go

Calls 1

toSessionMethod · 0.95

Tested by

no test coverage detected