Optimizing template cache by using an application config ***
This commit is contained in:
		@ -2,7 +2,10 @@ package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"go-udemy-web-1/pkg/config"
 | 
			
		||||
	"go-udemy-web-1/pkg/handlers"
 | 
			
		||||
	"go-udemy-web-1/pkg/render"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net/http"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@ -10,8 +13,22 @@ const portNumber = ":8080"
 | 
			
		||||
 | 
			
		||||
// main is the main application function
 | 
			
		||||
func main() {
 | 
			
		||||
	http.HandleFunc("/", handlers.Home)
 | 
			
		||||
	http.HandleFunc("/about", handlers.About)
 | 
			
		||||
	var app config.AppConfig
 | 
			
		||||
 | 
			
		||||
	tc, err := render.CreateTemplateCache()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Fatal("cannot create template cache")
 | 
			
		||||
	}
 | 
			
		||||
	app.TemplateCahce = tc
 | 
			
		||||
	app.UseCache = false
 | 
			
		||||
 | 
			
		||||
	repo := handlers.NewRepo(&app)
 | 
			
		||||
	handlers.NewHandlers(repo)
 | 
			
		||||
 | 
			
		||||
	render.NewTemplates(&app)
 | 
			
		||||
 | 
			
		||||
	http.HandleFunc("/", handlers.Repo.Home)
 | 
			
		||||
	http.HandleFunc("/about", handlers.Repo.About)
 | 
			
		||||
 | 
			
		||||
	fmt.Printf("Starting application on port %s\n", portNumber)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user