package server import ( "fmt" "local/router" "net/http" ) func (s *Server) Routes() error { wildcard := router.Wildcard endpoints := []struct { path string handler http.HandlerFunc }{ { path: "/", handler: s.root, }, { path: fmt.Sprintf("notes/%s%s", wildcard, wildcard), handler: s.authenticate(s.notes), }, { path: fmt.Sprintf("edit/%s%s", wildcard, wildcard), handler: s.authenticate(s.edit), }, { path: fmt.Sprintf("delete/%s%s", wildcard, wildcard), handler: s.authenticate(s.delete), }, { path: fmt.Sprintf("submit/%s%s", wildcard, wildcard), handler: s.authenticate(s.submit), }, { path: fmt.Sprintf("create/%s%s", wildcard, wildcard), handler: s.authenticate(s.create), }, { path: fmt.Sprintf("search"), handler: s.authenticate(s.search), }, } for _, endpoint := range endpoints { if err := s.Add(endpoint.path, endpoint.handler); err != nil { return err } } return nil } func (s *Server) root(w http.ResponseWriter, r *http.Request) { r.URL.Path = "/notes" http.Redirect(w, r, r.URL.String(), http.StatusPermanentRedirect) }