func ProjectGetOne(ctx *echo.Context) error { interactor := ctx.Get("ProjectInteractor").(*usecases.ProjectInteractor) projId := ctx.P(0) result := interactor.GetOne(projId) return ctx.JSON(http.StatusOK, result) }
func EnvironmentGetOne(ctx *echo.Context) error { interactor := ctx.Get("EnvironmentInteractor").(*usecases.EnvironmentInteractor) envId := ctx.P(0) result := interactor.GetEnvironmentById(envId) return ctx.JSON(http.StatusOK, result) }
func RenderStatic(c echo.Context) error { a, err := Asset(fmt.Sprintf("static%s", c.P(0))) if err != nil { panic(err) } return c.String(http.StatusOK, string(a)) }
// GetOne tag func (*TagsController) GetOne(c echo.Context) error { var model models.Tag ret, err := model.GetOne(c.P(0)) if err != nil { return c.JSON(400, utils.ErrMarshal(err.Error())) } return c.JSON(200, ret) }
// Single shows single page func (*SiteController) Single(c echo.Context) error { var site models.Site ret, err := site.Single(c.P(0)) if err != nil { return c.Render(400, "404", err) } return c.Render(200, "index", ret) }
func GetTokenLinks(c echo.Context) error { userToken := c.P(0) matchSpecific := func(b string) bool { return b == userToken } linksResponse, err := getTokenLinks(matchSpecific, uriBuilder(c)) if err != nil { return err } return c.JSON(http.StatusOK, linksResponse) }
func UserUpdate(ctx *echo.Context) error { interactor := ctx.Get("UserInteractor").(*usecases.UserInteractor) user := &entities.User{} if err := ctx.Bind(user); err != nil { return ctx.JSON(http.StatusBadRequest, "user: unable to parse") } user.Id = ctx.P(0) result := interactor.Update(user) return ctx.JSON(http.StatusOK, result) }
func EditHandlerPost(c echo.Context) error { filepath := c.P(0) eolIndex, _ := strconv.Atoi(c.FormValue("eol")) content := c.FormValue("content") convertedContent, err := eol.LineEnding(eolIndex).Apply(content) if err != nil { convertedContent = content log.Println("Error while converting EOL. Saving without conversion.") } ioutil.WriteFile(filepath, []byte(convertedContent), 0644) c.Set("editorView", NewEditorView(filepath, content)) return EditHandler(c) }
func ProjectUpdate(ctx *echo.Context) error { interactor := ctx.Get("ProjectInteractor").(*usecases.ProjectInteractor) projId := ctx.P(0) proj := interactor.GetOne(projId) if err := ctx.Bind(proj); err != nil { return ctx.JSON(http.StatusBadRequest, "project: unable to parse") } result := interactor.Update(proj) return ctx.JSON(http.StatusOK, result) }
// Find one app func (r App) Get(c *echo.Context, s *dokku.Dokku) error { name := c.P(0) app, err := s.Apps.Find(name) if err != nil { return err } if app == nil { return c.NoContent(http.StatusNotFound) } return c.JSONIndent(http.StatusOK, app, "", " ") }
func EnvironmentUpdate(ctx *echo.Context) error { interactor := ctx.Get("EnvironmentInteractor").(*usecases.EnvironmentInteractor) envId := ctx.P(0) env := interactor.GetEnvironmentById(envId) if err := ctx.Bind(env); err != nil { return ctx.JSON(http.StatusBadRequest, "environment: unable to parse") } result := interactor.Update(env) return ctx.JSON(http.StatusOK, result) }
func DownloadFile(c echo.Context) error { fileToken := c.P(0) src, err := persistence.FindFile([]byte(fileToken)) if err != nil { return err } defer src.Close() res := c.Response() if _, err := io.Copy(res.Writer(), src); err != nil { return err } return nil }
func EditHandler(c echo.Context) error { var ev *EditorView ev, ok := c.Get("editorView").(*EditorView) if !ok { log.Println("reading file") filepath := c.P(0) content, err := ioutil.ReadFile(filepath) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "Unable to read requested file") } ev = NewEditorView(filepath, string(content)) ev.CurrentLineEnding = eol.DetectDefault(ev.Content, eol.OSDefault()) log.Println(ev.CurrentLineEnding.Description()) } return c.Render(http.StatusOK, "base", ev) }
// Update tag func (*TagsController) Update(c echo.Context) error { var model models.Tag var payload models.Tag if err := c.Bind(&payload); err != nil { return c.JSON(400, utils.ErrMarshal(err.Error())) } iss := 1 payload.UpdatedBy = iss ret, err := model.Update(c.P(0), payload) if err != nil { return c.JSON(400, utils.ErrMarshal(err.Error())) } return c.JSON(200, ret) }
// Update post func (*PostsController) Update(c echo.Context) error { var model models.Post var payload models.PostPayload var status = c.QueryParam("status") if err := c.Bind(&payload); err != nil { return c.JSON(400, utils.ErrMarshal(err.Error())) } iss := 1 payload.UpdatedBy = iss ret, err := model.Update(c.P(0), payload, status) if err != nil { return c.JSON(400, utils.ErrMarshal(err.Error())) } return c.JSON(200, ret) }
func (tl *TeamLeader) listHandler(c *echo.Context) error { path := Path(c.P(0)) freshRps := make([]*RemoteService, 0) rps, ok := tl.machines[path] if !ok { c.JSON(http.StatusOK, freshRps) return nil } now := time.Now().Unix() for _, rp := range rps { if rp.LastHeartBeat+TimeOutLimit >= now { freshRps = append(freshRps, rp) } } for i, j := 0, len(freshRps)-1; i < j; i, j = i+1, j-1 { freshRps[i], freshRps[j] = freshRps[j], freshRps[i] } tl.machines[path] = freshRps c.JSON(http.StatusOK, freshRps) return nil }
func (tl *TeamLeader) joinHandler(c *echo.Context) error { servicePort := c.Request().FormValue("servicePort") host := c.Request().Host if strings.Contains(host, ":") { host = host[0:strings.Index(host, ":")] } location := ServiceLocation(host + ":" + servicePort) path := Path(c.P(0)) // println(path, ":", location) rps, ok := tl.machines[path] if !ok { rps = make([]*RemoteService, 0) } found := false for _, rp := range rps { if rp.ServiceLocation == location { rp.LastHeartBeat = time.Now().Unix() found = true break } } if !found { rps = append(rps, &RemoteService{ ServiceLocation: location, LastHeartBeat: time.Now().Unix(), }) } tl.machines[path] = rps c.JSON(http.StatusAccepted, tl.machines) // id, _ := strconv.Atoi(c.Param("url")) // utils.WriteJson(c, http.StatusOK, infos) // c.String(http.StatusOK, c.P(0)+" runs at "+location.String()+".") return nil }
func (a *Application) verifyEmail(c *echo.Context) error { user := a.Redis.GetUser(c.P(0)) fmt.Println(c.P(0)) fmt.Println(user) if user.EmailVerificationString == c.P(1) { user.EmailVerified = true user.EmailVerifiedDate = time.Now().UTC() user.ModifyDate = time.Now().UTC() userJSON, err := json.Marshal(user) if err != nil { fmt.Println(err) } else { a.Redis.UpdateUser(user.Id, string(userJSON)) } return c.Redirect(302, "/login?verified=true") } return c.Redirect(302, "/login?verified=false") }
func getUser(c *echo.Context) error { return c.JSON(http.StatusOK, users[c.P(0)]) }
func (a *Application) userAPI(c *echo.Context) error { return c.JSON(http.StatusOK, a.Redis.GetUser(domain.ShaHashString(c.P(0)))) }