Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2a4040

Browse files
committed
bugfix
1 parent 81eeeeb commit d2a4040

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/http/controller/index.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ func (IndexController) Index(ctx echo.Context) error {
6262
resources := logic.DefaultResource.FindBy(ctx, 10)
6363

6464
books := logic.DefaultGoBook.FindBy(ctx, 24)
65-
bookNum := 8
66-
bookStart := rand.Intn(len(books) - bookNum)
67-
books = books[bookStart : bookStart+bookNum]
65+
if len(books) > 8 {
66+
bookNum := 8
67+
bookStart := rand.Intn(len(books) - bookNum)
68+
books = books[bookStart : bookStart+bookNum]
69+
}
6870

6971
return render(ctx, "index.html", map[string]interface{}{"topics": topicsList, "articles": recentArticles, "likeflags": likeFlags, "resources": resources, "books": books})
7072
}

0 commit comments

Comments
 (0)