返回 DeepSeek-Reasonix
image_replay_warning.go
根目录 / internal / control / image_replay_warning.go
1 package control
2
3 import (
4 "context"
5 "sync"
6 )
7
8 type imageReplayWarningsKey struct{}
9
10 // Admission owns warning lifetime across sampling rounds. Only redacted causes
11 // are remembered; image processing still retries on every request.
12 type imageReplayWarnings struct {
13 mu sync.Mutex
14 seen map[string]struct{}
15 }
16
17 func withImageReplayWarnings(ctx context.Context) context.Context {
18 return context.WithValue(ctx, imageReplayWarningsKey{}, &imageReplayWarnings{seen: make(map[string]struct{})})
19 }
20
21 func (w *imageReplayWarnings) first(detail string) bool {
22 w.mu.Lock()
23 defer w.mu.Unlock()
24 if _, ok := w.seen[detail]; ok {
25 return false
26 }
27 w.seen[detail] = struct{}{}
28 return true
29 }
30
30 lines GO