Skip to content

Commit 070d454

Browse files
authored
Use the built-in max/min to simplify the code (#7081)
Signed-off-by: xiaoxiangirl <[email protected]>
1 parent 2f0fc62 commit 070d454

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

modules/caddyhttp/caddyauth/basicauth.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,7 @@ func (c *Cache) makeRoom() {
236236
// the cache is on a long tail, we can save a lot of CPU
237237
// time by doing a whole bunch of deletions now and then
238238
// we won't have to do them again for a while
239-
numToDelete := len(c.cache) / 10
240-
if numToDelete < 1 {
241-
numToDelete = 1
242-
}
239+
numToDelete := max(len(c.cache)/10, 1)
243240
for deleted := 0; deleted <= numToDelete; deleted++ {
244241
// Go maps are "nondeterministic" not actually random,
245242
// so although we could just chop off the "front" of the

modules/caddyhttp/reverseproxy/selectionpolicies.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,7 @@ func (r RandomChoiceSelection) Validate() error {
219219

220220
// Select returns an available host, if any.
221221
func (r RandomChoiceSelection) Select(pool UpstreamPool, _ *http.Request, _ http.ResponseWriter) *Upstream {
222-
k := r.Choose
223-
if k > len(pool) {
224-
k = len(pool)
225-
}
222+
k := min(r.Choose, len(pool))
226223
choices := make([]*Upstream, k)
227224
for i, upstream := range pool {
228225
if !upstream.Available() {

0 commit comments

Comments
 (0)