change the main.go place
This commit is contained in:
		@ -1,37 +0,0 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"html/template"
 | 
			
		||||
	"net/http"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const portNumber = ":8080"
 | 
			
		||||
 | 
			
		||||
// Home is the about page handler
 | 
			
		||||
func Home(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	renderTemplate(w, "home.page.tmpl")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// About is the about page handler
 | 
			
		||||
func About(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	renderTemplate(w, "about.page.tmpl")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func renderTemplate(w http.ResponseWriter, tmpl string) {
 | 
			
		||||
	parsedTemplate, _ := template.ParseFiles("../..//templates/" + tmpl)
 | 
			
		||||
	err := parsedTemplate.Execute(w, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		fmt.Println("error parsing template:", err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// main is the main application function
 | 
			
		||||
func main() {
 | 
			
		||||
	http.HandleFunc("/", Home)
 | 
			
		||||
	http.HandleFunc("/about", About)
 | 
			
		||||
 | 
			
		||||
	fmt.Printf("Starting application on port %s\n", portNumber)
 | 
			
		||||
 | 
			
		||||
	_ = http.ListenAndServe(portNumber, nil)
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user