func (s *WalkthroughService) Register(h *hitch.Hitch) error { var err error listMiddlewares := []func(http.Handler) http.Handler{} postMiddlewares := []func(http.Handler) http.Handler{} getMiddlewares := []func(http.Handler) http.Handler{} putMiddlewares := []func(http.Handler) http.Handler{} deleteMiddlewares := []func(http.Handler) http.Handler{} listMiddlewares, postMiddlewares, getMiddlewares, putMiddlewares, deleteMiddlewares = beforeWalkthroughServiceRegister() if err != nil { return err } h.Get("/api/walkthrough", s.walkthroughListHandler(), listMiddlewares...) h.Post("/api/walkthrough", s.walkthroughPostHandler(), postMiddlewares...) h.Get("/api/walkthrough/:id", s.walkthroughGetHandler(), getMiddlewares...) h.Put("/api/walkthrough/:id", s.walkthroughPutHandler(), putMiddlewares...) h.Delete("/api/walkthrough/:id", s.walkthroughDeleteHandler(), deleteMiddlewares...) afterWalkthroughServiceRegister(s, h) return err }
func (s *UserService) Register(h *hitch.Hitch) error { var err error postMiddlewares := []func(http.Handler) http.Handler{} getMiddlewares := []func(http.Handler) http.Handler{} putMiddlewares := []func(http.Handler) http.Handler{} deleteMiddlewares := []func(http.Handler) http.Handler{} // HOOK: beforeUserServiceRegister() if err != nil { return err } h.Post("/api/user", s.userPostHandler(), postMiddlewares...) h.Get("/api/user/:id", s.userGetHandler(), getMiddlewares...) h.Put("/api/user/:id", s.userPutHandler(), putMiddlewares...) h.Delete("/api/user/:id", s.userDeleteHandler(), deleteMiddlewares...) afterUserServiceRegister(h) return err }
func afterUserServiceRegister(h *hitch.Hitch) { h.Get("/api/user", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { sess := ab.GetSession(r) if sess["uid"] != "" { db := ab.GetDB(r) user, err := LoadUser(db, sess["uid"]) ab.MaybeFail(r, http.StatusInternalServerError, err) ab.Render(r). JSON(user) } })) }