Mercurial > gemma
comparison pkg/controllers/stretches.go @ 5207:c4e295b2d6a3 new-fwa
Some code simplification.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 11 May 2020 11:57:48 +0200 |
parents | 23addd19a6e2 |
children | 142ac550bd9a |
comparison
equal
deleted
inserted
replaced
5206:23addd19a6e2 | 5207:c4e295b2d6a3 |
---|---|
20 "encoding/csv" | 20 "encoding/csv" |
21 "fmt" | 21 "fmt" |
22 "log" | 22 "log" |
23 "net/http" | 23 "net/http" |
24 "runtime" | 24 "runtime" |
25 "strings" | |
26 "sync" | 25 "sync" |
27 "time" | 26 "time" |
28 | 27 |
29 "github.com/gorilla/mux" | 28 "github.com/gorilla/mux" |
30 | 29 |
291 } | 290 } |
292 | 291 |
293 if len(loaded) == 0 { | 292 if len(loaded) == 0 { |
294 http.Error( | 293 http.Error( |
295 rw, | 294 rw, |
296 fmt.Sprintf("No bottleneck loaded: %v", joinErrors(errors)), | 295 fmt.Sprintf("No bottleneck loaded: %v", common.JoinErrors(errors)), |
297 http.StatusInternalServerError, | 296 http.StatusInternalServerError, |
298 ) | 297 ) |
299 return | 298 return |
300 } | 299 } |
301 | 300 |
426 // Too late for HTTP status message. | 425 // Too late for HTTP status message. |
427 log.Printf("error: %v\n", err) | 426 log.Printf("error: %v\n", err) |
428 } | 427 } |
429 } | 428 } |
430 | 429 |
431 func joinErrors(errors []error) string { | |
432 var b strings.Builder | |
433 for _, err := range errors { | |
434 if b.Len() > 0 { | |
435 b.WriteString(", ") | |
436 } | |
437 b.WriteString(err.Error()) | |
438 } | |
439 return b.String() | |
440 } | |
441 | |
442 func stretchAvailabilty(rw http.ResponseWriter, req *http.Request) { | 430 func stretchAvailabilty(rw http.ResponseWriter, req *http.Request) { |
443 | 431 |
444 vars := mux.Vars(req) | 432 vars := mux.Vars(req) |
445 stretch := vars["kind"] == "stretch" | 433 stretch := vars["kind"] == "stretch" |
446 name := vars["name"] | 434 name := vars["name"] |
539 } | 527 } |
540 | 528 |
541 if len(loaded) == 0 { | 529 if len(loaded) == 0 { |
542 http.Error( | 530 http.Error( |
543 rw, | 531 rw, |
544 fmt.Sprintf("No bottleneck loaded: %v", joinErrors(errors)), | 532 fmt.Sprintf("No bottleneck loaded: %v", common.JoinErrors(errors)), |
545 http.StatusInternalServerError, | 533 http.StatusInternalServerError, |
546 ) | 534 ) |
547 return | 535 return |
548 } | 536 } |
549 | 537 |