Optimizing template cache by using an application config ***
This commit is contained in:
		@ -1,16 +1,37 @@
 | 
			
		||||
package handlers
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"go-udemy-web-1/pkg/config"
 | 
			
		||||
	"go-udemy-web-1/pkg/render"
 | 
			
		||||
	"net/http"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// 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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Home is the about page handler
 | 
			
		||||
func Home(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
func (m *Repository) Home(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	render.RenderTemplate(w, "home.page.tmpl")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// About is the about page handler
 | 
			
		||||
func About(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
func (m *Repository) About(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	render.RenderTemplate(w, "about.page.tmpl")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user