Skip to content

Commit

Permalink
randomize client
Browse files Browse the repository at this point in the history
  • Loading branch information
timburks committed Oct 18, 2024
1 parent 22c0dde commit c97bc28
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions cmd/stores-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"math/rand/v2"

pb "github.com/bobadojo/go/pkg/stores/v1/storespb"
"golang.org/x/oauth2/google"
Expand Down Expand Up @@ -93,33 +95,46 @@ func run() error {
ctx = metadata.AppendToOutgoingContext(ctx, "Authorization", fmt.Sprintf("Bearer %s", *token))
}

// Contact the server and print out its response.
r, err := c.FindStores(ctx, &pb.FindStoresRequest{
minLat := 39.0 + float32(rand.Uint32()%100)/100.0
minLng := -85.0 + float32(rand.Uint32()%100)/100.0

deltaLat := float32(0.5)
deltaLng := float32(0.5)

req := &pb.FindStoresRequest{
Bounds: &pb.BoundingBox{
Max: &pb.Location{
Latitude: 26.2,
Longitude: -80,
Latitude: minLat + deltaLat,
Longitude: minLng + deltaLng,
},
Min: &pb.Location{
Latitude: 26.1,
Longitude: -81,
Latitude: minLat,
Longitude: minLng,
},
},
})
}
log.Printf("%+v", req)

// Contact the server and print out its response.
r, err := c.FindStores(ctx, req)
if err != nil {
log.Fatalf("could not greet: %v", err)
return err
}
log.Printf("Stores: %d", len(r.Stores))
log.Printf("%d stores", r.Count)
for i, s := range r.Stores {
log.Printf("%v", s)

r2, err := c.GetStore(ctx, &pb.GetStoreRequest{
Name: s.Name,
})
if err != nil {
return err
}
log.Printf("%d: %+v", i, r2)

b, err := json.Marshal(r2)
if err != nil {
return err
}
log.Printf("%d: %s", i, string(b))

}
return nil
}

0 comments on commit c97bc28

Please sign in to comment.