-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): Implement delete app functionality as an HTTP endpoint bac…
- Loading branch information
1 parent
fcc9330
commit b82f426
Showing
16 changed files
with
305 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package server | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/pyroscope-io/pyroscope/pkg/server/httputils" | ||
"github.com/pyroscope-io/pyroscope/pkg/storage" | ||
"net/http" | ||
) | ||
|
||
type AppInfo struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
type DeleteAppInput struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
func (c *Controller) getAppsHandler() http.HandlerFunc { | ||
return NewGetAppsHandler(c.storage, c.httpUtils) | ||
} | ||
|
||
func NewGetAppsHandler(s storage.AppGetter, httpUtils httputils.Utils) func(w http.ResponseWriter, r *http.Request) { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
apps, err := s.GetApps(r.Context()) | ||
if err != nil { | ||
httpUtils.WriteError(r, w, http.StatusInternalServerError, err, "") | ||
return | ||
} | ||
res := make([]AppInfo, 0, len(apps.Apps)) | ||
for _, app := range apps.Apps { | ||
it := AppInfo{ | ||
Name: app.Name, | ||
} | ||
res = append(res, it) | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
httpUtils.WriteResponseJSON(r, w, res) | ||
} | ||
} | ||
|
||
func (c *Controller) getAppNames() http.HandlerFunc { | ||
return NewGetAppNamesHandler(c.storage, c.httpUtils) | ||
} | ||
|
||
func NewGetAppNamesHandler(s storage.AppNameGetter, httpUtils httputils.Utils) func(w http.ResponseWriter, r *http.Request) { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
appNames := s.GetAppNames(r.Context()) | ||
w.WriteHeader(http.StatusOK) | ||
httpUtils.WriteResponseJSON(r, w, appNames) | ||
} | ||
} | ||
|
||
func (c *Controller) deleteAppsHandler() http.HandlerFunc { | ||
return NewDeleteAppHandler(c.storage, c.httpUtils) | ||
} | ||
|
||
func NewDeleteAppHandler(s storage.AppDeleter, httpUtils httputils.Utils) func(w http.ResponseWriter, r *http.Request) { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
var payload DeleteAppInput | ||
|
||
err := json.NewDecoder(r.Body).Decode(&payload) | ||
if err != nil { | ||
httpUtils.WriteError(r, w, http.StatusBadRequest, err, "") | ||
return | ||
} | ||
|
||
err = s.DeleteApp(r.Context(), payload.Name) | ||
if err != nil { | ||
// TODO how to distinguish | ||
// it was a bad request | ||
// or an internal server error | ||
httpUtils.WriteError(r, w, http.StatusInternalServerError, err, "") | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusOK) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.