From e6412921951704f69b12ad018775b14c790b89c0 Mon Sep 17 00:00:00 2001 From: Flynn Date: Wed, 11 Sep 2024 17:29:46 -0400 Subject: [PATCH] Make requests include /center/ or /edge/ depending on which cell is in play. Signed-off-by: Flynn --- assets/html/index.html | 5 ++++- pkg/faces/faceserver.go | 13 +++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/assets/html/index.html b/assets/html/index.html index 229aaed..d06b44b 100644 --- a/assets/html/index.html +++ b/assets/html/index.html @@ -1259,7 +1259,10 @@

Faces

for (row = 0; row < 4; row++) { for (col = 0; col < 4; col++) { - let cell = new Cell(logger, sw, podSet, `../face/cell/`, $("cells"), row, col) + let isCenter = ((row === 1 || row === 2) && (col === 1 || col === 2)) + let cellURL = isCenter ? `../face/center/` : `../face/edge/` + + let cell = new Cell(logger, sw, podSet, cellURL, $("cells"), row, col) cells.push(cell) } $("cells").innerHTML += "
" diff --git a/pkg/faces/faceserver.go b/pkg/faces/faceserver.go index 4207de8..c04b5a4 100644 --- a/pkg/faces/faceserver.go +++ b/pkg/faces/faceserver.go @@ -22,6 +22,7 @@ import ( "fmt" "io" "net/http" + "strings" "time" "github.com/BuoyantIO/faces-demo/v2/pkg/utils" @@ -63,10 +64,10 @@ func (srv *FaceServer) SetupFromEnvironment() { fmt.Printf("%s %s: colorService %v\n", time.Now().Format(time.RFC3339), srv.Name, srv.colorService) } -func (srv *FaceServer) makeRequest(user string, userAgent string, service string, keyword string) *FaceResponse { +func (srv *FaceServer) makeRequest(user string, userAgent string, service string, keyword string, subrequest string) *FaceResponse { start := time.Now() - url := fmt.Sprintf("http://%s/", service) + url := fmt.Sprintf("http://%s/%s/", service, subrequest) if srv.debugEnabled { fmt.Printf("%s %s: %s starting\n", time.Now().Format(time.RFC3339), srv.Name, url) @@ -178,6 +179,10 @@ func (srv *FaceServer) faceGetHandler(r *http.Request, rstat *BaseRequestStatus) StatusCode: http.StatusOK, } + // Our request URL should start with /center/ or /edge/, and we want to + // propagate that to our smiley and color services. + subrequest := strings.Split(r.URL.Path, "/")[1] + errors := []string{} var smiley string var color string @@ -207,11 +212,11 @@ func (srv *FaceServer) faceGetHandler(r *http.Request, rstat *BaseRequestStatus) colorCh := make(chan *FaceResponse) go func() { - smileyCh <- srv.makeRequest(user, userAgent, srv.smileyService, "smiley") + smileyCh <- srv.makeRequest(user, userAgent, srv.smileyService, "smiley", subrequest) }() go func() { - colorCh <- srv.makeRequest(user, userAgent, srv.colorService, "color") + colorCh <- srv.makeRequest(user, userAgent, srv.colorService, "color", subrequest) }() // Wait for the responses from both services