2024-06-26 20:06:32 +00:00
|
|
|
package handlers
|
2024-06-26 19:56:58 +00:00
|
|
|
|
|
|
|
import (
|
2024-06-27 12:03:43 +00:00
|
|
|
"go-udemy-web-1/pkg/config"
|
2024-06-28 08:48:52 +00:00
|
|
|
"go-udemy-web-1/pkg/models"
|
2024-06-26 20:06:32 +00:00
|
|
|
"go-udemy-web-1/pkg/render"
|
2024-06-26 19:56:58 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2024-06-27 12:03:43 +00:00
|
|
|
// Repo the repository used by the handlers
|
|
|
|
var Repo *Repository
|
|
|
|
|
|
|
|
// Repository is the repository type
|
|
|
|
type Repository struct {
|
|
|
|
App *config.AppConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewRepo creates a new repository
|
|
|
|
func NewRepo(a *config.AppConfig) *Repository {
|
|
|
|
return &Repository{
|
|
|
|
App: a,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewHandlers sets the repository for the handlers
|
|
|
|
func NewHandlers(r *Repository) {
|
|
|
|
Repo = r
|
|
|
|
}
|
|
|
|
|
2024-06-26 19:56:58 +00:00
|
|
|
// Home is the about page handler
|
2024-06-27 12:03:43 +00:00
|
|
|
func (m *Repository) Home(w http.ResponseWriter, r *http.Request) {
|
2024-06-28 08:48:52 +00:00
|
|
|
render.RenderTemplate(w, "home.page.tmpl", &models.TemplateData{})
|
2024-06-26 19:56:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// About is the about page handler
|
2024-06-27 12:03:43 +00:00
|
|
|
func (m *Repository) About(w http.ResponseWriter, r *http.Request) {
|
2024-06-28 08:40:47 +00:00
|
|
|
// perform some logic
|
|
|
|
stringMap := make(map[string]string)
|
|
|
|
stringMap["test"] = "Hello world!"
|
|
|
|
// send the data to the template
|
2024-06-28 08:48:52 +00:00
|
|
|
render.RenderTemplate(w, "about.page.tmpl", &models.TemplateData{StringMap: stringMap})
|
2024-06-26 19:56:58 +00:00
|
|
|
}
|