LoadRateConfig reads and JSON-unmarshals a [RateConfig] from the file at path.
(path string)
| 536 | |
| 537 | // LoadRateConfig reads and JSON-unmarshals a [RateConfig] from the file at path. |
| 538 | func LoadRateConfig(path string) (RateConfig, error) { |
| 539 | if path == "" { |
| 540 | return RateConfig{}, errors.New("rate config path is empty") |
| 541 | } |
| 542 | b, err := os.ReadFile(path) |
| 543 | if err != nil { |
| 544 | return RateConfig{}, fmt.Errorf("error reading rate config: %w", err) |
| 545 | } |
| 546 | var rc RateConfig |
| 547 | if err := json.Unmarshal(b, &rc); err != nil { |
| 548 | return RateConfig{}, fmt.Errorf("error parsing rate config: %w", err) |
| 549 | } |
| 550 | return rc, nil |
| 551 | } |
| 552 | |
| 553 | // LoadAndApplyRateConfig reads a [RateConfig] from the file at path and |
| 554 | // applies it to the server via [Server.UpdateRateLimits]. |
searching dependent graphs…