diff --git a/lessons/215/go-app/main.go b/lessons/215/go-app/main.go index ea3bdcca9..0ba48a746 100644 --- a/lessons/215/go-app/main.go +++ b/lessons/215/go-app/main.go @@ -50,5 +50,5 @@ func (ms *MyServer) getHealth(w http.ResponseWriter, req *http.Request) { func (ms *MyServer) getDevices(w http.ResponseWriter, req *http.Request) { device := Device{Id: 1, Mac: "EF-2B-C4-F5-D6-34", Firmware: "2.1.5"} - renderJSON(w, &device, 200) + renderJSON(w, device, 200) } diff --git a/lessons/215/go-app/main_bench_test.go b/lessons/215/go-app/main_bench_test.go new file mode 100644 index 000000000..20521c135 --- /dev/null +++ b/lessons/215/go-app/main_bench_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "net/http" + "net/http/httptest" + "testing" +) + +func BenchmarkGetDevicesParallel(b *testing.B) { + ms := &MyServer{} + b.ReportAllocs() + + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + req := httptest.NewRequest("GET", "/api/devices", nil) + rec := httptest.NewRecorder() + + ms.getDevices(rec, req) + + res := rec.Result() + if res.StatusCode != http.StatusOK { + b.Fatalf("expected status %d, got %d", http.StatusOK, res.StatusCode) + } + res.Body.Close() + } + }) +}