func()

in pkg/api/api.go [85:130]


func (h *APIHandler) UpdateOdds(
	percentDuplicate,
	percentTooMany,
	percentNonIndex,
	percentTooLarge uint,
) error {
	h.configMu.Lock()
	defer h.configMu.Unlock()

	if int((percentDuplicate + percentTooMany + percentNonIndex)) > len(h.ActionOdds) {
		return fmt.Errorf("Total of percents can't be greater than %d", len(h.ActionOdds))
	}
	if int(percentTooLarge) > len(h.MethodOdds) {
		return fmt.Errorf("percent TooLarge cannot be greater than %d", len(h.MethodOdds))
	}

	// Fill in ActionOdds
	n := 0
	for i := uint(0); i < percentDuplicate; i++ {
		h.ActionOdds[n] = http.StatusConflict
		n++
	}
	for i := uint(0); i < percentTooMany; i++ {
		h.ActionOdds[n] = http.StatusTooManyRequests
		n++
	}
	for i := uint(0); i < percentNonIndex; i++ {
		h.ActionOdds[n] = http.StatusNotAcceptable
		n++
	}
	for ; n < len(h.ActionOdds); n++ {
		h.ActionOdds[n] = http.StatusOK
	}

	// Fill in MethodOdds
	n = 0
	for i := uint(0); i < percentTooLarge; i++ {
		h.MethodOdds[n] = http.StatusRequestEntityTooLarge
		n++
	}
	for ; n < len(h.MethodOdds); n++ {
		h.MethodOdds[n] = http.StatusOK
	}

	return nil
}