From a592ef037c843a0c681889a79294eedd4d8f9fa9 Mon Sep 17 00:00:00 2001 From: Ben Sully Date: Thu, 21 Sep 2023 07:49:38 +0100 Subject: [PATCH] Remove ping and echo handlers These were left over from the initial app scaffolding. --- pkg/plugin/resources.go | 37 ------------------------------------ pkg/plugin/resources_test.go | 20 ------------------- 2 files changed, 57 deletions(-) diff --git a/pkg/plugin/resources.go b/pkg/plugin/resources.go index 2f81e408..6f9c48cc 100644 --- a/pkg/plugin/resources.go +++ b/pkg/plugin/resources.go @@ -12,41 +12,6 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend/resource/httpadapter" ) -// /api/plugins/app-with-backend/resources/ping - -// handlePing is an example HTTP GET resource that returns a {"message": "ok"} JSON response. -func (a *App) handlePing(w http.ResponseWriter, req *http.Request) { - w.Header().Add("Content-Type", "application/json") - if _, err := w.Write([]byte(`{"message": "pong"}`)); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - log.DefaultLogger.Info("ping received") - w.WriteHeader(http.StatusOK) -} - -// handleEcho is an example HTTP POST resource that accepts a JSON with a "message" key and -// returns to the client whatever it is sent. -func (a *App) handleEcho(w http.ResponseWriter, req *http.Request) { - if req.Method != http.MethodPost { - http.Error(w, "method not allowed", http.StatusMethodNotAllowed) - return - } - var body struct { - Message string `json:"message"` - } - if err := json.NewDecoder(req.Body).Decode(&body); err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - w.Header().Add("Content-Type", "application/json") - if err := json.NewEncoder(w).Encode(body); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - w.WriteHeader(http.StatusOK) -} - func newOpenAIProxy() http.Handler { return &httputil.ReverseProxy{ Rewrite: func(r *httputil.ProxyRequest) { @@ -107,8 +72,6 @@ func (app *App) handleVectorSearch(w http.ResponseWriter, req *http.Request) { // registerRoutes takes a *http.ServeMux and registers some HTTP handlers. func (a *App) registerRoutes(mux *http.ServeMux) { - mux.HandleFunc("/ping", a.handlePing) - mux.HandleFunc("/echo", a.handleEcho) mux.Handle("/openai/", newOpenAIProxy()) mux.HandleFunc("/vector/search", a.handleVectorSearch) } diff --git a/pkg/plugin/resources_test.go b/pkg/plugin/resources_test.go index 0d9d5731..75ab2ab2 100644 --- a/pkg/plugin/resources_test.go +++ b/pkg/plugin/resources_test.go @@ -48,26 +48,6 @@ func TestCallResource(t *testing.T) { expStatus int expBody []byte }{ - { - name: "get ping 200", - method: http.MethodGet, - path: "ping", - expStatus: http.StatusOK, - }, - { - name: "get echo 405", - method: http.MethodGet, - path: "echo", - expStatus: http.StatusMethodNotAllowed, - }, - { - name: "post echo 200", - method: http.MethodPost, - path: "echo", - body: []byte(`{"message":"ok"}`), - expStatus: http.StatusOK, - expBody: []byte(`{"message":"ok"}`), - }, { name: "get non existing handler 404", method: http.MethodGet,