1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00

Merge pull request #45 from hugmouse/fix-no-hypha-connection-reset

Panic fix (#44)
This commit is contained in:
Timur Ismagilov 2021-03-09 07:28:24 +05:00 committed by GitHub
commit d2792ff83d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

12
main.go
View File

@ -85,8 +85,16 @@ func handlerUpdateHeaderLinks(w http.ResponseWriter, rq *http.Request) {
// Redirect to a random hypha.
func handlerRandom(w http.ResponseWriter, rq *http.Request) {
log.Println(rq.URL)
var randomHyphaName string
i := rand.Intn(hyphae.Count())
var (
randomHyphaName string
amountOfHyphae int = hyphae.Count()
)
if amountOfHyphae == 0 {
HttpErr(w, http.StatusNotFound, util.HomePage, "There are no hyphae",
"It is not possible to display a random hypha because the wiki does not contain any hyphae")
return
}
i := rand.Intn(amountOfHyphae)
for h := range hyphae.YieldExistingHyphae() {
if i == 0 {
randomHyphaName = h.Name