Skip to content

Commit

Permalink
chore: filter requests and responses
Browse files Browse the repository at this point in the history
  • Loading branch information
pgautier404 committed Aug 13, 2024
1 parent 2060721 commit 6a44b80
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions examples/middleware-example/timing_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"github.com/momentohq/client-sdk-go/momento"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -41,11 +42,17 @@ func timer(timerChan chan string, log logger.MomentoLogger) {
}

func (mw *timingMiddleware) OnRequest(requestId uint64, theRequest interface{}, metadata context.Context) {
mw.timerChan <- fmt.Sprintf("start:%d:%d", requestId, hrtime.Now())
switch theRequest.(type) {
case *momento.GetRequest, *momento.SetRequest:
mw.timerChan <- fmt.Sprintf("start:%d:%d", requestId, hrtime.Now())
}
}

func (mw *timingMiddleware) OnResponse(requestId uint64, theResponse map[string]string) {
mw.timerChan <- fmt.Sprintf("end:%d:%d", requestId, hrtime.Now())
switch theResponse["responseType"] {
case "*responses.GetHit", "*responses.GetMiss", "*responses.SetSuccess":
mw.timerChan <- fmt.Sprintf("end:%d:%d", requestId, hrtime.Now())
}
}

func NewTimingMiddleware(log logger.MomentoLogger) *timingMiddleware {
Expand Down

0 comments on commit 6a44b80

Please sign in to comment.