ParseRateLimitHeader parses the X-Wave-RateLimit header Format: X-Wave-RateLimit: req= , reqlimit= , preq= , preqlimit= , reset= Example: X-Wave-RateLimit: req=180, reqlimit=200, preq=45, preqlimit=50, reset=1727818382 -
(header string)
| 563 | // - preqlimit: maximum premium requests allowed in the window |
| 564 | // - reset: unix timestamp (epoch seconds) when the rate limit window resets |
| 565 | func ParseRateLimitHeader(header string) *RateLimitInfo { |
| 566 | if header == "" { |
| 567 | return nil |
| 568 | } |
| 569 | |
| 570 | info := &RateLimitInfo{} |
| 571 | parts := strings.Split(header, ",") |
| 572 | |
| 573 | for _, part := range parts { |
| 574 | part = strings.TrimSpace(part) |
| 575 | kv := strings.SplitN(part, "=", 2) |
| 576 | if len(kv) != 2 { |
| 577 | continue |
| 578 | } |
| 579 | |
| 580 | key := strings.TrimSpace(kv[0]) |
| 581 | value := strings.TrimSpace(kv[1]) |
| 582 | |
| 583 | switch key { |
| 584 | case "req": |
| 585 | if val, err := fmt.Sscanf(value, "%d", &info.Req); err == nil && val == 1 { |
| 586 | // Successfully parsed |
| 587 | } |
| 588 | case "reqlimit": |
| 589 | if val, err := fmt.Sscanf(value, "%d", &info.ReqLimit); err == nil && val == 1 { |
| 590 | // Successfully parsed |
| 591 | } |
| 592 | case "preq": |
| 593 | if val, err := fmt.Sscanf(value, "%d", &info.PReq); err == nil && val == 1 { |
| 594 | // Successfully parsed |
| 595 | } |
| 596 | case "preqlimit": |
| 597 | if val, err := fmt.Sscanf(value, "%d", &info.PReqLimit); err == nil && val == 1 { |
| 598 | // Successfully parsed |
| 599 | } |
| 600 | case "reset": |
| 601 | if val, err := fmt.Sscanf(value, "%d", &info.ResetEpoch); err == nil && val == 1 { |
| 602 | // Successfully parsed |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | return info |
| 608 | } |
| 609 | |
| 610 | func AreModelsCompatible(apiType, model1, model2 string) bool { |
| 611 | if model1 == model2 { |
no outgoing calls
no test coverage detected