Skip to content

Commit

Permalink
Rename API endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Luis Lucas committed Nov 30, 2018
1 parent 981c615 commit ed55a77
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gossip/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type DummyProcessor struct {

func (d DummyProcessor) Process(b *protocol.BatchSnapshots) {
for i := 0; i < len(b.Snapshots); i++ {
res, err := http.Get(fmt.Sprintf("http://127.0.0.1:8888/?nodeType=auditor&id=%d", b.Snapshots[0].Snapshot.Version))
res, err := http.Get(fmt.Sprintf("http://127.0.0.1:8888/stat/?nodeType=auditor&id=%d", b.Snapshots[0].Snapshot.Version))
if err != nil || res == nil {
log.Debugf("Error contacting service with error %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion gossip/publisher/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (p *Publisher) Process(b *protocol.BatchSnapshots) {

req := fasthttp.AcquireRequest()
// TODO: Implement send to different endpoints
req.SetRequestURI(p.Config.SendTo[0] + "/publish")
req.SetRequestURI(p.Config.SendTo[0] + "/batch")
req.Header.SetMethodBytes([]byte("POST"))
req.Header.Add("Content-Type", "application/json")
req.SetBody(body)
Expand Down
10 changes: 6 additions & 4 deletions tests/gossip/test_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func statHandler(w http.ResponseWriter, r *http.Request) {
atomic.AddUint64(&count, 1)
}

func putHandler(kv *kv) func(http.ResponseWriter, *http.Request) {
func postBatchHandler(kv *kv) func(http.ResponseWriter, *http.Request) {

return func(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
Expand All @@ -115,7 +115,8 @@ func putHandler(kv *kv) func(http.ResponseWriter, *http.Request) {
http.Error(w, "Invalid request method", http.StatusMethodNotAllowed)
}
}
func getHandler(kv *kv) func(http.ResponseWriter, *http.Request) {

func getSnapshotHandler(kv *kv) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
q := r.URL.Query()
Expand All @@ -135,6 +136,7 @@ func getHandler(kv *kv) func(http.ResponseWriter, *http.Request) {
http.Error(w, "Invalid request method", http.StatusMethodNotAllowed)
}
}

func main() {
var store kv

Expand All @@ -155,7 +157,7 @@ func main() {
}()

http.HandleFunc("/stat", statHandler)
http.HandleFunc("/put", putHandler(&store))
http.HandleFunc("/get", getHandler(&store))
http.HandleFunc("/batch", postBatchHandler(&store))
http.HandleFunc("/snapshot/{id}", getSnapshotHandler(&store))
log.Fatal(http.ListenAndServe("127.0.0.1:8888", nil))
}

0 comments on commit ed55a77

Please sign in to comment.