okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffaufrefactor(cli): share cursor traversal across paged resources155c8e8

main
612 B25 linesraw
1// Package daemon adapts protocol resources and streams for the native client.
2package daemon
3
4// Walk pages without hiding endpoint-specific validation or accumulation.
5func walkPages[Page any](fetch func(*string) (Page, *string, error), consume func(Page) error, cursorField string) error {
6	var cursor *string
7	seen := map[string]bool{}
8	for {
9		page, next, err := fetch(cursor)
10		if err != nil {
11			return err
12		}
13		if err := consume(page); err != nil {
14			return err
15		}
16		if next == nil {
17			return nil
18		}
19		if seen[*next] {
20			return fieldError(cursorField)
21		}
22		seen[*next] = true
23		cursor = next
24	}
25}