Files
lingniu-vehicle-ingest/vehicle-data-platform/apps/api/internal/platform/schema_gate.go

24 lines
475 B
Go

package platform
import "sync"
// schemaReadyGate serializes schema probes and caches only a successful result.
// Request cancellation and transient database failures must remain retryable.
type schemaReadyGate struct {
mu sync.Mutex
ready bool
}
func (gate *schemaReadyGate) ensure(check func() error) error {
gate.mu.Lock()
defer gate.mu.Unlock()
if gate.ready {
return nil
}
if err := check(); err != nil {
return err
}
gate.ready = true
return nil
}