func NewPriorityRateLimiter(
	apiToPriority map[string]int,
	priorityToRateLimiters map[int]RateLimiter,
) *PriorityRateLimiterImpl {
	priorities := make([]int, 0, len(priorityToRateLimiters))
	for priority := range priorityToRateLimiters {
		priorities = append(priorities, priority)
	}
	sort.Slice(priorities, func(i, j int) bool {
		return priorities[i] < priorities[j]
	})
	priorityToIndex := make(map[int]int, len(priorityToRateLimiters))
	rateLimiters := make([]RateLimiter, 0, len(priorityToRateLimiters))
	for index, priority := range priorities {
		priorityToIndex[priority] = index
		rateLimiters = append(rateLimiters, priorityToRateLimiters[priority])
	}
	for _, priority := range apiToPriority {
		if _, ok := priorityToRateLimiters[priority]; !ok {
			panic("API to priority & priority to rate limiter does not match")
		}
	}
	return &PriorityRateLimiterImpl{
		apiToPriority:          apiToPriority,
		priorityToRateLimiters: priorityToRateLimiters,
		priorityToIndex: priorityToIndex,
		rateLimiters:    rateLimiters,
	}
}
NewPriorityRateLimiter returns a new rate limiter that can handle dynamic
configuration updates
package quotas
import (
	"context"
	"fmt"
	"sort"
	"time"
)
type (
	PriorityRateLimiterImpl struct {
		apiToPriority          map[string]int
		priorityToRateLimiters map[int]RateLimiter
		priorityToIndex map[int]int
		rateLimiters    []RateLimiter
	}
)
var _ RequestRateLimiter = (*PriorityRateLimiterImpl)(nil)