Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 23:30 UTC
Use the built-in max/min to simplify the code (#7081)
Signed-off-by: xiaoxiangirl <caojiaqiao@outlook.com>
曹家巧 committed
Jun 20, 2025 at 06:39 UTC
070d454c0d164f943ee19e608708046a066f8a2d
2 files changed
+2
-8
modules/caddyhttp/caddyauth/basicauth.go
+1
-4
@@ -236,10 +236,7 @@ func (c *Cache) makeRoom() {
236
// the cache is on a long tail, we can save a lot of CPU
237
// time by doing a whole bunch of deletions now and then
238
// 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)
240
for deleted := 0; deleted <= numToDelete; deleted++ {
241
// Go maps are "nondeterministic" not actually random,
242
// so although we could just chop off the "front" of the
modules/caddyhttp/reverseproxy/selectionpolicies.go
+1
-4
@@ -219,10 +219,7 @@ func (r RandomChoiceSelection) Validate() error {
219
220
// Select returns an available host, if any.
221
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))
223
choices := make([]*Upstream, k)
224
for i, upstream := range pool {
225
if !upstream.Available() {