Skip to content

Commit

Permalink
Remove ping and echo handlers
Browse files Browse the repository at this point in the history
These were left over from the initial app scaffolding.
  • Loading branch information
sd2k committed Sep 21, 2023
1 parent dfa4505 commit a592ef0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 57 deletions.
37 changes: 0 additions & 37 deletions pkg/plugin/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
20 changes: 0 additions & 20 deletions pkg/plugin/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a592ef0

Please sign in to comment.