package main
import ("fmt"
"net/http"
"html/template")
type User struct {
name string
age uint16
money int16
avg_grades,heppiness float64
}
func (u User) getAllInfo() string {
return fmt.Sprintf("User name is: %s.He is %d he has is money %d ",u.name,u.age,u.money)
}
func (u *User) setNewName(newName string) {
u.name = newName
}
func home_page(w http.ResponseWriter, r *http.Request){
bob := User {"Bob",25,-50,4.2,0.8}
//bob.setNewName("Alex")
//fmt.Fprintf(w, bob.getAllInfo())
tmpl, _ := template.parseFiles("templates/home_page.html")
tmpl.Execute(w, bob)
}
func contacts_page(w http.ResponseWriter, r *http.Request){
fmt.Fprintf(w,"Contacts page")
}
func hanlde_request(){
http.HandleFunc("/", home_page)
http.HandleFunc("/contacts/", contacts_page)
http.ListenAndServe(":8080",nil)
}
func main() {
//bob := User {name: "Bob",age:25, money: -50 avg_grades:4.2,heppiness:0.8}
hanlde_request()
}
===========================================================================================
Вывод в браузер через метод Fprintf работает, а через template.parseFiles ошибка.
===========================================================================================
go версия 1.17.8 windows 7 процессор amd
===========================================================================================
ошибка при запуске
.\main.go:27:35: not enough arguments in call to "html/template".parseFiles
have (string)
want (*"html/template".Template, func(string) (string, []byte, error), ...string)