func Route(name string) httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { hash := cookie.Get(r, "hash") u, b := Users[hash] if len(hash) == 0 || !b { http.Redirect(w, r, "/", http.StatusFound) return } c := controllers.Controller{w, r, ps, *Templates, u} methodVal := reflect.ValueOf(&c).MethodByName(name) methodIface := methodVal.Interface() method := methodIface.(func()) method() fmt.Println(name) } }
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { fmt.Println("Index") hash := cookie.Get(r, "hash") u, b := Users[hash] if len(hash) == 0 || !b { err = Templates.ExecuteTemplate(w, "index", nil) checkerr(err) return } list, err := u.List() if err != nil { fmt.Println(err) return } err = Templates.ExecuteTemplate(w, "list", map[string][]user.FileList{"List": list}) if err != nil { fmt.Println(err) return } }