func (h *DeleteDomain) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error { a, err := findApp(ctx, h) if err != nil { return err } vars := httpx.Vars(ctx) name := vars["hostname"] d, err := h.DomainsFirst(empire.DomainsQuery{Hostname: &name, App: a}) if err != nil { if err == gorm.RecordNotFound { return &ErrorResource{ Status: http.StatusNotFound, ID: "not_found", Message: "Couldn't find that domain name.", } } return err } if err = h.DomainsDestroy(d); err != nil { return err } return NoContent(w) }
func (h *DeleteProcesses) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error { vars := httpx.Vars(ctx) pid := vars["pid"] if vars["ptype"] != "" { return errNotImplemented("Restarting a process type is currently not implemented.") } a, err := findApp(ctx, h) if err != nil { return err } m, err := findMessage(r) if err != nil { return err } if err := h.Restart(ctx, empire.RestartOpts{ User: UserFromContext(ctx), App: a, PID: pid, Message: m, }); err != nil { return err } return NoContent(w) }
func findApp(ctx context.Context, e interface { AppsFind(empire.AppsQuery) (*empire.App, error) }) (*empire.App, error) { vars := httpx.Vars(ctx) name := vars["app"] a, err := e.AppsFind(empire.AppsQuery{Name: &name}) reporter.AddContext(ctx, "app", a.Name) return a, err }
func findCert(ctx context.Context, app *empire.App, f CertFinder) (*empire.Certificate, error) { vars := httpx.Vars(ctx) name := vars["cert"] cert, err := f.CertificatesFirst(ctx, empire.CertificatesQuery{ ID: &name, App: app, }) if err != nil { return cert, err } return cert, err }
func (h *DeleteProcesses) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error { vars := httpx.Vars(ctx) pid := vars["pid"] if vars["ptype"] != "" { return errNotImplemented("Restarting a process type is currently not implemented.") } a, err := findApp(ctx, h) if err != nil { return err } err = h.ProcessesRestart(ctx, a, pid) if err != nil { return err } return NoContent(w) }
func (h *GetRelease) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error { a, err := findApp(ctx, h) if err != nil { return err } vars := httpx.Vars(ctx) vers, err := strconv.Atoi(vars["version"]) if err != nil { return err } rel, err := h.ReleasesFirst(empire.ReleasesQuery{App: a, Version: &vers}) if err != nil { return err } w.WriteHeader(200) return Encode(w, newRelease(rel)) }