Using pat for routing
This commit is contained in:
		@ -27,10 +27,13 @@ func main() {
 | 
			
		||||
 | 
			
		||||
	render.NewTemplates(&app)
 | 
			
		||||
 | 
			
		||||
	http.HandleFunc("/", handlers.Repo.Home)
 | 
			
		||||
	http.HandleFunc("/about", handlers.Repo.About)
 | 
			
		||||
 | 
			
		||||
	fmt.Printf("Starting application on port %s\n", portNumber)
 | 
			
		||||
 | 
			
		||||
	_ = http.ListenAndServe(portNumber, nil)
 | 
			
		||||
	srv := &http.Server{
 | 
			
		||||
		Addr:    portNumber,
 | 
			
		||||
		Handler: routes(&app),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = srv.ListenAndServe()
 | 
			
		||||
	log.Fatal(err)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										18
									
								
								cmd/web/routes.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								cmd/web/routes.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"go-udemy-web-1/pkg/config"
 | 
			
		||||
	"go-udemy-web-1/pkg/handlers"
 | 
			
		||||
	"net/http"
 | 
			
		||||
 | 
			
		||||
	"github.com/bmizerany/pat"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func routes(app *config.AppConfig) http.Handler {
 | 
			
		||||
	mux := pat.New()
 | 
			
		||||
 | 
			
		||||
	mux.Get("/", http.HandlerFunc(handlers.Repo.Home))
 | 
			
		||||
	mux.Get("/about", http.HandlerFunc(handlers.Repo.About))
 | 
			
		||||
 | 
			
		||||
	return mux
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user