Buenas trato de hacer la parte final y no me funciona. abajo el codigo. main.go: package main
import ( "fmt" "html/template" "log" "net/http" )
type User struct { UserName string Age int Active bool Admin bool }
func (self User) AdminPermissionAllowed(key string) bool { return self.Active && self.Admin && key == "y" }
func main() { port := ":5000" http.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) { template, err := template.ParseFiles("templates/index.html") if err != nil { panic(err) } user := User{"luis", 39, true, true} template.Execute(rw, user) }) fmt.Println("Server is running on", port) log.Fatal(http.ListenAndServe(port, nil)) }
index.html: <!DOCTYPE html>
Document
hola {{.UserName}} <!--{{.AdminPermissionAllowed}}--> {{if .AdminPermissionAllowed "y"}}
Eres Administrador
{{else}}No eres Administrador
{{end}}