MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / parseDurationValue

Function parseDurationValue

sdk/cliproxy/auth/conductor.go:5411–5472  ·  view source on GitHub ↗
(val any)

Source from the content-addressed store, hash-verified

5409}
5410
5411func parseDurationValue(val any) time.Duration {
5412 switch v := val.(type) {
5413 case time.Duration:
5414 if v <= 0 {
5415 return 0
5416 }
5417 return v
5418 case int:
5419 if v <= 0 {
5420 return 0
5421 }
5422 return time.Duration(v) * time.Second
5423 case int32:
5424 if v <= 0 {
5425 return 0
5426 }
5427 return time.Duration(v) * time.Second
5428 case int64:
5429 if v <= 0 {
5430 return 0
5431 }
5432 return time.Duration(v) * time.Second
5433 case uint:
5434 if v == 0 {
5435 return 0
5436 }
5437 return time.Duration(v) * time.Second
5438 case uint32:
5439 if v == 0 {
5440 return 0
5441 }
5442 return time.Duration(v) * time.Second
5443 case uint64:
5444 if v == 0 {
5445 return 0
5446 }
5447 return time.Duration(v) * time.Second
5448 case float32:
5449 if v <= 0 {
5450 return 0
5451 }
5452 return time.Duration(float64(v) * float64(time.Second))
5453 case float64:
5454 if v <= 0 {
5455 return 0
5456 }
5457 return time.Duration(v * float64(time.Second))
5458 case json.Number:
5459 if i, err := v.Int64(); err == nil {
5460 if i <= 0 {
5461 return 0
5462 }
5463 return time.Duration(i) * time.Second
5464 }
5465 if f, err := v.Float64(); err == nil && f > 0 {
5466 return time.Duration(f * float64(time.Second))
5467 }
5468 case string:

Callers 1

durationFromMetadataFunction · 0.85

Calls 1

parseDurationStringFunction · 0.85

Tested by

no test coverage detected