phoenix/views/pages/index.go
Ivan R. 6d25c4e8af
feat!: migrate to net/http
With the release of Go 1.22, the standard library now has
all the necessary functions that allow us to abandon Gin.

I hope this rewrite will lower the entry barrier for new developers.
As a nice bonus, the size of the program has decreased from 20 to 15.4 MB.

To solve issue #81, request logging has been improved.
Now all errors are displayed in the logs.
2024-03-25 15:52:18 +05:00

31 lines
597 B
Go

package pages
import (
"net/http"
"github.com/ordinary-dev/phoenix/database"
log "github.com/sirupsen/logrus"
)
func ShowMainPage(w http.ResponseWriter, _ *http.Request) {
// Get a list of groups with links
var groups []database.Group
result := database.DB.
Model(&database.Group{}).
Preload("Links").
Find(&groups)
if result.Error != nil {
ShowError(w, http.StatusInternalServerError, result.Error)
return
}
err := Render("index.html.tmpl", w, map[string]any{
"description": "Self-hosted start page.",
"groups": groups,
})
if err != nil {
log.Error(err)
}
}