[gold] baseline_server.go: Add /json/v2/expectations route.

Bug: skia:10522
Change-Id: If0abd50c341a5249050510d505281a007bba35a8
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/327323
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
Commit-Queue: Leandro Lovisolo <lovisolo@google.com>
diff --git a/golden/cmd/baseline_server/baseline_server.go b/golden/cmd/baseline_server/baseline_server.go
index 7aaa724..45b2b82 100644
--- a/golden/cmd/baseline_server/baseline_server.go
+++ b/golden/cmd/baseline_server/baseline_server.go
@@ -149,12 +149,25 @@
 		})
 	}
 
+	v2 := func(rpcRoute string, handlerFunc http.HandlerFunc) *mux.Route {
+		counter := metrics2.GetCounter(web.RPCCallCounterMetric, map[string]string{
+			// For consistency, we remove the /json/vN from all routes when adding them in the metrics.
+			"route":   strings.TrimPrefix(rpcRoute, "/json/v2"),
+			"version": "v2",
+		})
+		return appRouter.HandleFunc(rpcRoute, func(w http.ResponseWriter, r *http.Request) {
+			counter.Inc(1)
+			handlerFunc(w, r)
+		})
+	}
+
 	// Serve the known hashes from GCS.
 	v0(shared.KnownHashesRoute, handlers.TextKnownHashesProxy).Methods("GET")
 	v1(shared.KnownHashesRouteV1, handlers.TextKnownHashesProxy).Methods("GET")
 	// Serve the expectations for the master branch and for CLs in progress.
 	v0(shared.ExpectationsRoute, handlers.BaselineHandlerV1).Methods("GET")
 	v1(shared.ExpectationsRouteV1, handlers.BaselineHandlerV1).Methods("GET")
+	v2(shared.ExpectationsRouteV2, handlers.BaselineHandlerV2).Methods("GET")
 	// TODO(lovisolo): Remove the below route once goldctl is fully migrated.
 	v0(shared.ExpectationsLegacyRoute, handlers.BaselineHandlerV1).Methods("GET")