diff --git a/pkg/acceptance/admin_test.go b/pkg/acceptance/admin_test.go index 66e139dd9120..4782e82e8090 100644 --- a/pkg/acceptance/admin_test.go +++ b/pkg/acceptance/admin_test.go @@ -26,7 +26,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/server/serverpb" "github.com/cockroachdb/cockroach/pkg/server/status" "github.com/cockroachdb/cockroach/pkg/ts/tspb" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/timeutil" ) @@ -44,7 +44,7 @@ func testAdminLossOfQuorumInner(t *testing.T, c cluster.Cluster, cfg cluster.Tes nodeIDs := make([]roachpb.NodeID, c.NumNodes()) for i := 0; i < c.NumNodes(); i++ { var details serverpb.DetailsResponse - if err := util.GetJSON(cluster.HTTPClient, c.URL(i)+"/_status/details/local", &details); err != nil { + if err := httputil.GetJSON(cluster.HTTPClient, c.URL(i)+"/_status/details/local", &details); err != nil { t.Fatal(err) } nodeIDs[i] = details.NodeID @@ -59,13 +59,13 @@ func testAdminLossOfQuorumInner(t *testing.T, c cluster.Cluster, cfg cluster.Tes // Retrieve node statuses. var nodes serverpb.NodesResponse - if err := util.GetJSON(cluster.HTTPClient, c.URL(0)+"/_status/nodes", &nodes); err != nil { + if err := httputil.GetJSON(cluster.HTTPClient, c.URL(0)+"/_status/nodes", &nodes); err != nil { t.Fatal(err) } for _, nodeID := range nodeIDs { var nodeStatus status.NodeStatus - if err := util.GetJSON(cluster.HTTPClient, c.URL(0)+"/_status/nodes/"+strconv.Itoa(int(nodeID)), &nodeStatus); err != nil { + if err := httputil.GetJSON(cluster.HTTPClient, c.URL(0)+"/_status/nodes/"+strconv.Itoa(int(nodeID)), &nodeStatus); err != nil { t.Fatal(err) } } @@ -80,7 +80,7 @@ func testAdminLossOfQuorumInner(t *testing.T, c cluster.Cluster, cfg cluster.Tes }, } var queryResponse tspb.TimeSeriesQueryResponse - if err := util.PostJSON(cluster.HTTPClient, c.URL(0)+"/ts/query", + if err := httputil.PostJSON(cluster.HTTPClient, c.URL(0)+"/ts/query", &queryRequest, &queryResponse); err != nil { t.Fatal(err) } diff --git a/pkg/acceptance/allocator_test.go b/pkg/acceptance/allocator_test.go index cec0a7f232da..8a705624a17d 100644 --- a/pkg/acceptance/allocator_test.go +++ b/pkg/acceptance/allocator_test.go @@ -87,7 +87,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/server/serverpb" "github.com/cockroachdb/cockroach/pkg/sql" "github.com/cockroachdb/cockroach/pkg/storage" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/timeutil" ) @@ -204,7 +204,7 @@ func (at *allocatorTest) stdDev() (float64, error) { var client http.Client var nodesResp serverpb.NodesResponse url := fmt.Sprintf("http://%s:%s/_status/nodes", host, adminPort) - if err := util.GetJSON(client, url, &nodesResp); err != nil { + if err := httputil.GetJSON(client, url, &nodesResp); err != nil { return 0, err } var replicaCounts stats.Float64Data diff --git a/pkg/acceptance/build_info_test.go b/pkg/acceptance/build_info_test.go index 3e910bea9bc0..95bdba9a4567 100644 --- a/pkg/acceptance/build_info_test.go +++ b/pkg/acceptance/build_info_test.go @@ -23,6 +23,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/acceptance/cluster" "github.com/cockroachdb/cockroach/pkg/server/serverpb" "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/httputil" ) func TestBuildInfo(t *testing.T) { @@ -39,7 +40,7 @@ func testBuildInfoInner(t *testing.T, c cluster.Cluster, cfg cluster.TestConfig) t.Fatalf("interrupted") default: } - return util.GetJSON(cluster.HTTPClient, c.URL(0)+"/_status/details/local", &details) + return httputil.GetJSON(cluster.HTTPClient, c.URL(0)+"/_status/details/local", &details) }) bi := details.BuildInfo diff --git a/pkg/acceptance/continuous_load_test.go b/pkg/acceptance/continuous_load_test.go index 60379ba3335f..457ccedd20e4 100644 --- a/pkg/acceptance/continuous_load_test.go +++ b/pkg/acceptance/continuous_load_test.go @@ -28,6 +28,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/acceptance/terrafarm" "github.com/cockroachdb/cockroach/pkg/server/status" "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/timeutil" ) @@ -74,7 +75,7 @@ func (cl continuousLoadTest) queryCount(f *terrafarm.Farmer) (float64, error) { var client http.Client var resp status.NodeStatus host := f.Nodes()[0] - if err := util.GetJSON(client, "http://"+host+":8080/_status/nodes/local", &resp); err != nil { + if err := httputil.GetJSON(client, "http://"+host+":8080/_status/nodes/local", &resp); err != nil { return 0, err } count, ok := resp.Metrics["sql.query.count"] diff --git a/pkg/acceptance/freeze_test.go b/pkg/acceptance/freeze_test.go index c0f1f5947b0f..c9c6d1502995 100644 --- a/pkg/acceptance/freeze_test.go +++ b/pkg/acceptance/freeze_test.go @@ -33,6 +33,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/server/serverpb" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/log" ) @@ -59,7 +60,7 @@ func postFreeze( log.Infof(context.Background(), "%+v", &resp) } } - err := util.StreamJSON( + err := httputil.StreamJSON( httpClient, c.URL(0)+"/_admin/v1/cluster/freeze", &serverpb.ClusterFreezeRequest{Freeze: freeze}, diff --git a/pkg/acceptance/gossip_peerings_test.go b/pkg/acceptance/gossip_peerings_test.go index a095230c6cab..d2d95641af96 100644 --- a/pkg/acceptance/gossip_peerings_test.go +++ b/pkg/acceptance/gossip_peerings_test.go @@ -30,6 +30,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/gossip" "github.com/cockroachdb/cockroach/pkg/internal/client" "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/timeutil" ) @@ -53,7 +54,7 @@ func checkGossip(t *testing.T, c cluster.Cluster, d time.Duration, f checkGossip var infoStatus gossip.InfoStatus for i := 0; i < c.NumNodes(); i++ { - if err := util.GetJSON(cluster.HTTPClient, c.URL(i)+"/_status/gossip/local", &infoStatus); err != nil { + if err := httputil.GetJSON(cluster.HTTPClient, c.URL(i)+"/_status/gossip/local", &infoStatus); err != nil { return err } if err := f(infoStatus.Infos); err != nil { diff --git a/pkg/acceptance/status_server_test.go b/pkg/acceptance/status_server_test.go index ab859ca9361d..043a3ce20cbe 100644 --- a/pkg/acceptance/status_server_test.go +++ b/pkg/acceptance/status_server_test.go @@ -30,7 +30,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/acceptance/cluster" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/server/serverpb" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/retry" ) @@ -82,7 +82,7 @@ func checkNode( } var details serverpb.DetailsResponse for _, urlID := range urlIDs { - if err := util.GetJSON(cluster.HTTPClient, c.URL(i)+"/_status/details/"+urlID, &details); err != nil { + if err := httputil.GetJSON(cluster.HTTPClient, c.URL(i)+"/_status/details/"+urlID, &details); err != nil { t.Fatal(errors.Errorf("unable to parse details - %s", err)) } if details.NodeID != expectedNodeID { @@ -108,7 +108,7 @@ func testStatusServerInner(t *testing.T, c cluster.Cluster, cfg cluster.TestConf idMap := make(map[int]roachpb.NodeID) for i := 0; i < c.NumNodes(); i++ { var details serverpb.DetailsResponse - if err := util.GetJSON(cluster.HTTPClient, c.URL(i)+"/_status/details/local", &details); err != nil { + if err := httputil.GetJSON(cluster.HTTPClient, c.URL(i)+"/_status/details/local", &details); err != nil { t.Fatal(err) } idMap[i] = details.NodeID diff --git a/pkg/server/admin_cluster_test.go b/pkg/server/admin_cluster_test.go index 59fecc5a2b43..6e37dc3c1f48 100644 --- a/pkg/server/admin_cluster_test.go +++ b/pkg/server/admin_cluster_test.go @@ -26,6 +26,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/server/serverpb" "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/leaktest" ) @@ -84,7 +85,7 @@ func TestAdminAPITableStats(t *testing.T) { // The new SQL table may not yet have split into its own range. Wait for // this to occur, and for full replication. util.SucceedsSoon(t, func() error { - if err := util.GetJSON(client, url, &tsResponse); err != nil { + if err := httputil.GetJSON(client, url, &tsResponse); err != nil { return err } if tsResponse.RangeCount != 1 { @@ -112,7 +113,7 @@ func TestAdminAPITableStats(t *testing.T) { // lower. tc.StopServer(1) - if err := util.GetJSON(client, url, &tsResponse); err != nil { + if err := httputil.GetJSON(client, url, &tsResponse); err != nil { t.Fatal(err) } if a, e := tsResponse.NodeCount, int64(nodeCount); a != e { @@ -137,5 +138,5 @@ func TestAdminAPITableStats(t *testing.T) { // timeout; however, in aggregate (or in stress tests) this will suffice for // detecting leaks. client.Timeout = 1 * time.Nanosecond - _ = util.GetJSON(client, url, &tsResponse) + _ = httputil.GetJSON(client, url, &tsResponse) } diff --git a/pkg/server/admin_test.go b/pkg/server/admin_test.go index f8d40f5f5567..5c29cda08ca1 100644 --- a/pkg/server/admin_test.go +++ b/pkg/server/admin_test.go @@ -45,6 +45,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/timeutil" @@ -981,14 +982,14 @@ func TestClusterFreeze(t *testing.T) { } path := s.AdminURL() + adminPrefix + "cluster/freeze" - if err := util.StreamJSON(cli, path, &req, &serverpb.ClusterFreezeResponse{}, cb); err != nil { + if err := httputil.StreamJSON(cli, path, &req, &serverpb.ClusterFreezeResponse{}, cb); err != nil { t.Fatal(err) } if aff := resp.RangesAffected; aff == 0 { t.Fatalf("expected affected ranges: %+v", resp) } - if err := util.StreamJSON(cli, path, &req, &serverpb.ClusterFreezeResponse{}, cb); err != nil { + if err := httputil.StreamJSON(cli, path, &req, &serverpb.ClusterFreezeResponse{}, cb); err != nil { t.Fatal(err) } } diff --git a/pkg/server/authentication_test.go b/pkg/server/authentication_test.go index ab25e8953e1a..8aa39f59ec8a 100644 --- a/pkg/server/authentication_test.go +++ b/pkg/server/authentication_test.go @@ -30,7 +30,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" "github.com/cockroachdb/cockroach/pkg/ts" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/protoutil" "github.com/gogo/protobuf/proto" @@ -52,7 +52,7 @@ func doHTTPReq( t.Fatalf("%s %s: error building request: %s", method, url, err) } if b != nil { - req.Header.Add(util.ContentTypeHeader, util.ProtoContentType) + req.Header.Add(httputil.ContentTypeHeader, httputil.ProtoContentType) } return client.Do(req) diff --git a/pkg/server/server.go b/pkg/server/server.go index d989a89a6634..de56914a0d1a 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -55,9 +55,11 @@ import ( "github.com/cockroachdb/cockroach/pkg/util" "github.com/cockroachdb/cockroach/pkg/util/envutil" "github.com/cockroachdb/cockroach/pkg/util/hlc" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/metric" "github.com/cockroachdb/cockroach/pkg/util/netutil" + "github.com/cockroachdb/cockroach/pkg/util/protoutil" "github.com/cockroachdb/cockroach/pkg/util/sdnotify" "github.com/cockroachdb/cockroach/pkg/util/stop" "github.com/cockroachdb/cockroach/pkg/util/timeutil" @@ -620,18 +622,18 @@ func (s *Server) Start(ctx context.Context) error { log.Event(ctx, "accepting connections") // Initialize grpc-gateway mux and context. - jsonpb := &util.JSONPb{ + jsonpb := &protoutil.JSONPb{ EnumsAsInts: true, EmitDefaults: true, Indent: " ", } - protopb := new(util.ProtoPb) + protopb := new(protoutil.ProtoPb) gwMux := gwruntime.NewServeMux( gwruntime.WithMarshalerOption(gwruntime.MIMEWildcard, jsonpb), - gwruntime.WithMarshalerOption(util.JSONContentType, jsonpb), - gwruntime.WithMarshalerOption(util.AltJSONContentType, jsonpb), - gwruntime.WithMarshalerOption(util.ProtoContentType, protopb), - gwruntime.WithMarshalerOption(util.AltProtoContentType, protopb), + gwruntime.WithMarshalerOption(httputil.JSONContentType, jsonpb), + gwruntime.WithMarshalerOption(httputil.AltJSONContentType, jsonpb), + gwruntime.WithMarshalerOption(httputil.ProtoContentType, protopb), + gwruntime.WithMarshalerOption(httputil.AltProtoContentType, protopb), ) gwCtx, gwCancel := context.WithCancel(s.AnnotateCtx(context.Background())) s.stopper.AddCloser(stop.CloserFn(gwCancel)) @@ -767,10 +769,10 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Disable caching of responses. w.Header().Set("Cache-control", "no-cache") - ae := r.Header.Get(util.AcceptEncodingHeader) + ae := r.Header.Get(httputil.AcceptEncodingHeader) switch { - case strings.Contains(ae, util.GzipEncoding): - w.Header().Set(util.ContentEncodingHeader, util.GzipEncoding) + case strings.Contains(ae, httputil.GzipEncoding): + w.Header().Set(httputil.ContentEncodingHeader, httputil.GzipEncoding) gzw := newGzipResponseWriter(w) defer gzw.Close() w = gzw diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index 7a23091fa24c..5229b2d0924a 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -42,6 +42,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" "github.com/cockroachdb/cockroach/pkg/util" "github.com/cockroachdb/cockroach/pkg/util/hlc" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/metric" @@ -199,7 +200,7 @@ func TestAcceptEncoding(t *testing.T) { return b }, }, - {util.GzipEncoding, + {httputil.GzipEncoding, func(b io.Reader) io.Reader { r, err := gzip.NewReader(b) if err != nil { @@ -215,14 +216,14 @@ func TestAcceptEncoding(t *testing.T) { t.Fatalf("could not create request: %s", err) } if d.acceptEncoding != "" { - req.Header.Set(util.AcceptEncodingHeader, d.acceptEncoding) + req.Header.Set(httputil.AcceptEncodingHeader, d.acceptEncoding) } resp, err := client.Do(req) if err != nil { t.Fatalf("could not make request to %s: %s", req.URL, err) } defer resp.Body.Close() - if ce := resp.Header.Get(util.ContentEncodingHeader); ce != d.acceptEncoding { + if ce := resp.Header.Get(httputil.ContentEncodingHeader); ce != d.acceptEncoding { t.Fatalf("unexpected content encoding: '%s' != '%s'", ce, d.acceptEncoding) } r := d.newReader(resp.Body) diff --git a/pkg/server/status.go b/pkg/server/status.go index 00b752bdc2cd..e5ca1978d06a 100644 --- a/pkg/server/status.go +++ b/pkg/server/status.go @@ -44,7 +44,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/server/serverpb" "github.com/cockroachdb/cockroach/pkg/server/status" "github.com/cockroachdb/cockroach/pkg/storage" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/syncutil" "github.com/cockroachdb/cockroach/pkg/util/timeutil" @@ -547,7 +547,7 @@ func (s *statusServer) RaftDebug( } func (s *statusServer) handleVars(w http.ResponseWriter, r *http.Request) { - w.Header().Set(util.ContentTypeHeader, util.PlaintextContentType) + w.Header().Set(httputil.ContentTypeHeader, httputil.PlaintextContentType) err := s.metricSource.PrintAsText(w) if err != nil { log.Error(r.Context(), err) diff --git a/pkg/server/status_test.go b/pkg/server/status_test.go index 4c8ccc709f92..07b0c684a057 100644 --- a/pkg/server/status_test.go +++ b/pkg/server/status_test.go @@ -44,6 +44,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" "github.com/cockroachdb/cockroach/pkg/ts" "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/stop" @@ -78,7 +79,7 @@ func TestStatusLocalStacks(t *testing.T) { } // TestStatusJson verifies that status endpoints return expected Json results. -// The content type of the responses is always util.JSONContentType. +// The content type of the responses is always httputil.JSONContentType. func TestStatusJson(t *testing.T) { defer leaktest.AfterTest(t)() s, _, _ := serverutils.StartServer(t, base.TestServerArgs{}) @@ -497,7 +498,7 @@ func TestSpanStatsResponse(t *testing.T) { } url := ts.AdminURL() + statusPrefix + "span" - if err := util.PostJSON(httpClient, url, &request, &response); err != nil { + if err := httputil.PostJSON(httpClient, url, &request, &response); err != nil { t.Fatal(err) } if a, e := int(response.RangeCount), ExpectedInitialRangeCount(); a != e { diff --git a/pkg/testutils/serverutils/test_server_shim.go b/pkg/testutils/serverutils/test_server_shim.go index 3363bc0cb931..4215e0826fac 100644 --- a/pkg/testutils/serverutils/test_server_shim.go +++ b/pkg/testutils/serverutils/test_server_shim.go @@ -42,8 +42,8 @@ import ( "github.com/cockroachdb/cockroach/pkg/rpc" "github.com/cockroachdb/cockroach/pkg/security" "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" - "github.com/cockroachdb/cockroach/pkg/util" "github.com/cockroachdb/cockroach/pkg/util/hlc" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/stop" ) @@ -161,7 +161,7 @@ func GetJSONProto(ts TestServerInterface, path string, response proto.Message) e if err != nil { return err } - return util.GetJSON(httpClient, ts.AdminURL()+path, response) + return httputil.GetJSON(httpClient, ts.AdminURL()+path, response) } // PostJSONProto uses the supplied client to POST request to the URL specified by @@ -171,7 +171,7 @@ func PostJSONProto(ts TestServerInterface, path string, request, response proto. if err != nil { return err } - return util.PostJSON(httpClient, ts.AdminURL()+path, request, response) + return httputil.PostJSON(httpClient, ts.AdminURL()+path, request, response) } // LookupRange returns the descriptor of the range containing key. diff --git a/pkg/testutils/testcluster/testcluster_test.go b/pkg/testutils/testcluster/testcluster_test.go index 1b8004f94638..4e2cc4ece9af 100644 --- a/pkg/testutils/testcluster/testcluster_test.go +++ b/pkg/testutils/testcluster/testcluster_test.go @@ -30,7 +30,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sqlbase" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/log" ) @@ -200,7 +200,7 @@ func TestStopServer(t *testing.T) { t.Fatal(err) } url := server1.AdminURL() + "/_admin/v1/health" - if err := util.GetJSON(httpClient1, url, &response); err != nil { + if err := httputil.GetJSON(httpClient1, url, &response); err != nil { t.Fatal(err) } @@ -223,7 +223,7 @@ func TestStopServer(t *testing.T) { // Verify HTTP and GRPC requests to server now fail. httpErrorText := "connection refused" - if err := util.GetJSON(httpClient1, url, &response); err == nil { + if err := httputil.GetJSON(httpClient1, url, &response); err == nil { t.Fatal("Expected HTTP Request to fail after server stopped") } else if !testutils.IsError(err, httpErrorText) { t.Fatalf("Expected error from server with text %q, got error with text %q", httpErrorText, err.Error()) @@ -242,7 +242,7 @@ func TestStopServer(t *testing.T) { t.Fatal(err) } url = tc.Server(0).AdminURL() + "/_admin/v1/health" - if err := util.GetJSON(httpClient1, url, &response); err != nil { + if err := httputil.GetJSON(httpClient1, url, &response); err != nil { t.Fatal(err) } } diff --git a/pkg/util/http.go b/pkg/util/httputil/http.go similarity index 99% rename from pkg/util/http.go rename to pkg/util/httputil/http.go index f8c51c39b6c3..8ecbbc71c7e1 100644 --- a/pkg/util/http.go +++ b/pkg/util/httputil/http.go @@ -14,7 +14,7 @@ // // Author: Spencer Kimball (spencer.kimball@gmail.com) -package util +package httputil import ( "bytes" diff --git a/pkg/util/jsonpb_marshal.go b/pkg/util/protoutil/jsonpb_marshal.go similarity index 97% rename from pkg/util/jsonpb_marshal.go rename to pkg/util/protoutil/jsonpb_marshal.go index c329c831c450..d3be893f72ae 100644 --- a/pkg/util/jsonpb_marshal.go +++ b/pkg/util/protoutil/jsonpb_marshal.go @@ -14,7 +14,7 @@ // // Author: Tamir Duberstein (tamird@gmail.com) -package util +package protoutil import ( "bytes" @@ -27,6 +27,8 @@ import ( "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/pkg/errors" + + "github.com/cockroachdb/cockroach/pkg/util/httputil" ) var _ gwruntime.Marshaler = (*JSONPb)(nil) @@ -38,7 +40,7 @@ type JSONPb jsonpb.Marshaler // ContentType implements gwruntime.Marshaler. func (*JSONPb) ContentType() string { - return "application/json" + return httputil.JSONContentType } // Marshal implements gwruntime.Marshaler. diff --git a/pkg/util/proto_marshal.go b/pkg/util/protoutil/marshaler.go similarity index 94% rename from pkg/util/proto_marshal.go rename to pkg/util/protoutil/marshaler.go index 92518376e09d..eade9852dd22 100644 --- a/pkg/util/proto_marshal.go +++ b/pkg/util/protoutil/marshaler.go @@ -14,7 +14,7 @@ // // Author: Tamir Duberstein (tamird@gmail.com) -package util +package protoutil import ( "io" @@ -24,7 +24,7 @@ import ( gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/pkg/errors" - "github.com/cockroachdb/cockroach/pkg/util/protoutil" + "github.com/cockroachdb/cockroach/pkg/util/httputil" ) var _ gwruntime.Marshaler = (*ProtoPb)(nil) @@ -34,13 +34,13 @@ type ProtoPb struct{} // ContentType implements gwruntime.Marshaler. func (*ProtoPb) ContentType() string { - return ProtoContentType + return httputil.ProtoContentType } // Marshal implements gwruntime.Marshaler. func (*ProtoPb) Marshal(v interface{}) ([]byte, error) { if p, ok := v.(proto.Message); ok { - return protoutil.Marshal(p) + return Marshal(p) } return nil, errors.Errorf("unexpected type %T does not implement %s", v, typeProtoMessage) } @@ -86,7 +86,7 @@ func (*ProtoPb) NewEncoder(w io.Writer) gwruntime.Encoder { // Encode implements gwruntime.Marshaler. func (e *protoEncoder) Encode(v interface{}) error { if p, ok := v.(proto.Message); ok { - bytes, err := protoutil.Marshal(p) + bytes, err := Marshal(p) if err == nil { _, err = e.w.Write(bytes) }