MCPcopy Create free account
hub / github.com/erpc/erpc / Validate

Method Validate

common/validation.go:264–310  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

262}
263
264func (s *SharedStateConfig) Validate() error {
265 if s.Connector != nil {
266 if err := s.Connector.Validate(); err != nil {
267 return err
268 }
269 } else {
270 return fmt.Errorf("sharedState.connector is required")
271 }
272 if s.FallbackTimeout == 0 {
273 return fmt.Errorf("sharedState.fallbackTimeout is required")
274 }
275 if s.FallbackTimeout.Duration() < 100*time.Millisecond {
276 return fmt.Errorf("sharedState.fallbackTimeout should be at least 100ms")
277 }
278 if s.LockTtl == 0 {
279 return fmt.Errorf("sharedState.lockTtl is required")
280 }
281 if s.LockTtl.Duration() < 1*time.Second {
282 return fmt.Errorf("sharedState.lockTtl should be at least 1s")
283 }
284
285 // Validate timeout relationships for the best-effort design
286 fallbackTimeout := s.FallbackTimeout.Duration()
287 lockTtl := s.LockTtl.Duration()
288 lockMaxWait := s.LockMaxWait.Duration()
289 updateMaxWait := s.UpdateMaxWait.Duration()
290
291 // LockTtl should be long enough to complete remote operations (get + set)
292 // It should be at least as long as FallbackTimeout to allow one remote operation
293 if lockTtl < fallbackTimeout {
294 return fmt.Errorf("sharedState.lockTtl (%v) should be at least as long as fallbackTimeout (%v) to complete remote operations",
295 lockTtl, fallbackTimeout)
296 }
297
298 // LockMaxWait and UpdateMaxWait are foreground budgets and should be much smaller than network timeouts
299 if lockMaxWait >= fallbackTimeout {
300 return fmt.Errorf("sharedState.lockMaxWait (%v) should be less than fallbackTimeout (%v) as it's a foreground latency budget",
301 lockMaxWait, fallbackTimeout)
302 }
303
304 if updateMaxWait >= fallbackTimeout {
305 return fmt.Errorf("sharedState.updateMaxWait (%v) should be less than fallbackTimeout (%v) as it's a foreground latency budget",
306 updateMaxWait, fallbackTimeout)
307 }
308
309 return nil
310}
311
312func (c *CacheConfig) Validate() error {
313 existingIds := make(map[string]bool)

Callers 1

Calls 3

ErrorfMethod · 0.80
ValidateMethod · 0.45
DurationMethod · 0.45

Tested by 1