Commit b71e9b9e authored by Janos Guljas's avatar Janos Guljas

use jsonhttp in pingpong api endpoint

parent 783f256d
......@@ -5,23 +5,29 @@
package api
import (
"fmt"
"net/http"
"time"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/gorilla/mux"
)
type pingpongResponse struct {
RTT time.Duration `json:"rtt"`
}
func (s *server) pingpongHandler(w http.ResponseWriter, r *http.Request) {
peerID := mux.Vars(r)["peer-id"]
ctx := r.Context()
rtt, err := s.Pingpong.Ping(ctx, peerID, "hey", "there", ",", "how are", "you", "?")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, "ping error", peerID, err)
jsonhttp.InternalServerError(w, err.Error())
return
}
s.metrics.PingRequestCount.Inc()
fmt.Fprintln(w, "RTT", rtt)
jsonhttp.OK(w, pingpongResponse{
RTT: rtt,
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment