From 205ba05feb3fd773d872b5ffbcad2d32c7f8bd6c Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Thu, 15 May 2025 17:54:23 +0200 Subject: [PATCH] fix usestdlibvars Signed-off-by: Matthieu MOREL --- .golangci.yml | 7 ++++ .../router/volume/volume_routes_test.go | 35 ++++++++++--------- api/server/server.go | 2 +- builder/remotecontext/remote.go | 2 +- client/request.go | 2 +- daemon/daemon_windows.go | 3 +- distribution/pull_v2_test.go | 4 +-- distribution/registry_unit_test.go | 4 +-- errdefs/http_helpers.go | 6 ++-- .../docker_cli_external_volume_driver_test.go | 2 +- .../docker_cli_registry_user_agent_test.go | 2 +- integration-cli/docker_cli_v2_only_test.go | 2 +- .../windows/overlay/ov_endpoint_windows.go | 11 +++--- .../windows/overlay/ov_network_windows.go | 7 ++-- .../windows/overlay/overlay_windows.go | 3 +- .../drivers/windows/overlay/peerdb_windows.go | 5 +-- libnetwork/drivers/windows/windows.go | 13 +++---- libnetwork/network_windows.go | 3 +- volume/drivers/proxy_test.go | 2 +- 19 files changed, 65 insertions(+), 50 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 82dc5878e2..2faa2ca1af 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -44,6 +44,7 @@ linters: - staticcheck - unconvert # Detects unnecessary type conversions. - unused + - usestdlibvars # Detects the possibility to use variables/constants from the Go standard library. - wastedassign # Detects wasted assignment statements. disable: @@ -164,6 +165,12 @@ linters: - record-error # check that `span.RecordError(err)` is called when an error is returned - set-status # check that `span.SetStatus(codes.Error, msg)` is called when an error is returned + usestdlibvars: + # Suggest the use of http.MethodXX. + http-method: true + # Suggest the use of http.StatusXX. + http-status-code: true + exclusions: paths: - volume/drivers/proxy.go # TODO: this is a generated file but with an invalid header, see https://github.com/moby/moby/pull/46274 diff --git a/api/server/router/volume/volume_routes_test.go b/api/server/router/volume/volume_routes_test.go index e8dc66f3be..bcaa1e7b29 100644 --- a/api/server/router/volume/volume_routes_test.go +++ b/api/server/router/volume/volume_routes_test.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "net/http" "net/http/httptest" "testing" @@ -20,7 +21,7 @@ import ( func callGetVolume(v *volumeRouter, name string) (*httptest.ResponseRecorder, error) { ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) vars := map[string]string{"name": name} - req := httptest.NewRequest("GET", fmt.Sprintf("/volumes/%s", name), nil) + req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/volumes/%s", name), nil) resp := httptest.NewRecorder() err := v.getVolumeByName(ctx, resp, req, vars) @@ -30,7 +31,7 @@ func callGetVolume(v *volumeRouter, name string) (*httptest.ResponseRecorder, er func callListVolumes(v *volumeRouter) (*httptest.ResponseRecorder, error) { ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) vars := map[string]string{} - req := httptest.NewRequest("GET", "/volumes", nil) + req := httptest.NewRequest(http.MethodGet, "/volumes", nil) resp := httptest.NewRecorder() err := v.getVolumesList(ctx, resp, req, vars) @@ -193,7 +194,7 @@ func TestCreateRegularVolume(t *testing.T) { assert.NilError(t, err) ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest("POST", "/volumes/create", &buf) + req := httptest.NewRequest(http.MethodPost, "/volumes/create", &buf) req.Header.Add("Content-Type", "application/json") resp := httptest.NewRecorder() @@ -231,7 +232,7 @@ func TestCreateSwarmVolumeNoSwarm(t *testing.T) { assert.NilError(t, err) ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest("POST", "/volumes/create", &buf) + req := httptest.NewRequest(http.MethodPost, "/volumes/create", &buf) req.Header.Add("Content-Type", "application/json") resp := httptest.NewRecorder() @@ -260,7 +261,7 @@ func TestCreateSwarmVolumeNotManager(t *testing.T) { assert.NilError(t, err) ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest("POST", "/volumes/create", &buf) + req := httptest.NewRequest(http.MethodPost, "/volumes/create", &buf) req.Header.Add("Content-Type", "application/json") resp := httptest.NewRecorder() @@ -292,7 +293,7 @@ func TestCreateVolumeCluster(t *testing.T) { assert.NilError(t, err) ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest("POST", "/volumes/create", &buf) + req := httptest.NewRequest(http.MethodPost, "/volumes/create", &buf) req.Header.Add("Content-Type", "application/json") resp := httptest.NewRecorder() @@ -339,7 +340,7 @@ func TestUpdateVolume(t *testing.T) { assert.NilError(t, err) ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest("POST", "/volumes/vol1/update?version=0", &buf) + req := httptest.NewRequest(http.MethodPost, "/volumes/vol1/update?version=0", &buf) req.Header.Add("Content-Type", "application/json") resp := httptest.NewRecorder() @@ -368,7 +369,7 @@ func TestUpdateVolumeNoSwarm(t *testing.T) { assert.NilError(t, err) ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest("POST", "/volumes/vol1/update?version=0", &buf) + req := httptest.NewRequest(http.MethodPost, "/volumes/vol1/update?version=0", &buf) req.Header.Add("Content-Type", "application/json") resp := httptest.NewRecorder() @@ -400,7 +401,7 @@ func TestUpdateVolumeNotFound(t *testing.T) { assert.NilError(t, err) ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest("POST", "/volumes/vol1/update?version=0", &buf) + req := httptest.NewRequest(http.MethodPost, "/volumes/vol1/update?version=0", &buf) req.Header.Add("Content-Type", "application/json") resp := httptest.NewRecorder() @@ -426,7 +427,7 @@ func TestVolumeRemove(t *testing.T) { } ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest("DELETE", "/volumes/vol1", nil) + req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil) resp := httptest.NewRecorder() err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"}) @@ -453,7 +454,7 @@ func TestVolumeRemoveSwarm(t *testing.T) { } ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest("DELETE", "/volumes/vol1", nil) + req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil) resp := httptest.NewRecorder() err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"}) @@ -470,7 +471,7 @@ func TestVolumeRemoveNotFoundNoSwarm(t *testing.T) { } ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest("DELETE", "/volumes/vol1", nil) + req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil) resp := httptest.NewRecorder() err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"}) @@ -487,7 +488,7 @@ func TestVolumeRemoveNotFoundNoManager(t *testing.T) { } ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest("DELETE", "/volumes/vol1", nil) + req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil) resp := httptest.NewRecorder() err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"}) @@ -511,7 +512,7 @@ func TestVolumeRemoveFoundNoSwarm(t *testing.T) { } ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest("DELETE", "/volumes/vol1", nil) + req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil) resp := httptest.NewRecorder() err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"}) @@ -534,7 +535,7 @@ func TestVolumeRemoveNoSwarmInUse(t *testing.T) { } ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest("DELETE", "/volumes/inuse", nil) + req := httptest.NewRequest(http.MethodDelete, "/volumes/inuse", nil) resp := httptest.NewRecorder() err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "inuse"}) @@ -562,7 +563,7 @@ func TestVolumeRemoveSwarmForce(t *testing.T) { } ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest("DELETE", "/volumes/vol1", nil) + req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil) resp := httptest.NewRecorder() err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"}) @@ -571,7 +572,7 @@ func TestVolumeRemoveSwarmForce(t *testing.T) { assert.Assert(t, errdefs.IsConflict(err)) ctx = context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req = httptest.NewRequest("DELETE", "/volumes/vol1?force=1", nil) + req = httptest.NewRequest(http.MethodDelete, "/volumes/vol1?force=1", nil) resp = httptest.NewRecorder() err = v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"}) diff --git a/api/server/server.go b/api/server/server.go index e626f269b2..c7ce275fec 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -60,7 +60,7 @@ func (s *Server) makeHTTPHandler(handler httputils.APIFunc, operation string) ht if err := handlerFunc(ctx, w, r, vars); err != nil { statusCode := httpstatus.FromError(err) - if statusCode >= 500 { + if statusCode >= http.StatusInternalServerError { log.G(ctx).Errorf("Handler for %s %s returned error: %v", r.Method, r.URL.Path, err) } // While we no longer support API versions older 1.24 [api.MinSupportedAPIVersion], diff --git a/builder/remotecontext/remote.go b/builder/remotecontext/remote.go index bb4047f3f4..ae3423a179 100644 --- a/builder/remotecontext/remote.go +++ b/builder/remotecontext/remote.go @@ -53,7 +53,7 @@ func GetWithStatusError(address string) (*http.Response, error) { } return nil, errdefs.System(err) } - if resp.StatusCode < 400 { + if resp.StatusCode < http.StatusBadRequest { return resp, nil } msg := fmt.Sprintf("failed to GET %s with status %s", address, resp.Status) diff --git a/client/request.go b/client/request.go index 4cc64350bd..dd95653a79 100644 --- a/client/request.go +++ b/client/request.go @@ -195,7 +195,7 @@ func (cli *Client) checkResponseErr(serverResp *http.Response) (retErr error) { if serverResp == nil { return nil } - if serverResp.StatusCode >= 200 && serverResp.StatusCode < 400 { + if serverResp.StatusCode >= http.StatusOK && serverResp.StatusCode < http.StatusBadRequest { return nil } defer func() { diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index 458969f9d2..fdcae75be8 100644 --- a/daemon/daemon_windows.go +++ b/daemon/daemon_windows.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "math" + "net/http" "path/filepath" "runtime" "strings" @@ -242,7 +243,7 @@ func (daemon *Daemon) initNetworkController(daemonCfg *config.Config, activeSand return errors.Wrap(err, "error obtaining controller instance") } - hnsresponse, err := hcsshim.HNSListNetworkRequest("GET", "", "") + hnsresponse, err := hcsshim.HNSListNetworkRequest(http.MethodGet, "", "") if err != nil { return err } diff --git a/distribution/pull_v2_test.go b/distribution/pull_v2_test.go index e509745ae7..bbc97429bc 100644 --- a/distribution/pull_v2_test.go +++ b/distribution/pull_v2_test.go @@ -297,9 +297,9 @@ func TestPullSchema2Config(t *testing.T) { t.Logf("HTTP %s %s", r.Method, r.URL.Path) defer r.Body.Close() switch { - case r.Method == "GET" && r.URL.Path == "/v2": + case r.Method == http.MethodGet && r.URL.Path == "/v2": w.WriteHeader(http.StatusOK) - case r.Method == "GET" && r.URL.Path == "/v2/library/testremotename/blobs/"+expectedDigest.String(): + case r.Method == http.MethodGet && r.URL.Path == "/v2/library/testremotename/blobs/"+expectedDigest.String(): tc.handler(int(callCount.Add(1)), w) default: w.WriteHeader(http.StatusNotFound) diff --git a/distribution/registry_unit_test.go b/distribution/registry_unit_test.go index 8d025410db..b7203a32f5 100644 --- a/distribution/registry_unit_test.go +++ b/distribution/registry_unit_test.go @@ -30,7 +30,7 @@ func (h *tokenPassThruHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) } if h.shouldSend401 == nil || h.shouldSend401(r.RequestURI) { w.Header().Set("WWW-Authenticate", `Bearer realm="foorealm"`) - w.WriteHeader(401) + w.WriteHeader(http.StatusUnauthorized) } } @@ -82,7 +82,7 @@ func TestTokenPassThruDifferentHost(t *testing.T) { tsredirect := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.RequestURI == "/v2/" { w.Header().Set("WWW-Authenticate", `Bearer realm="foorealm"`) - w.WriteHeader(401) + w.WriteHeader(http.StatusUnauthorized) return } http.Redirect(w, r, ts.URL+r.URL.Path, http.StatusMovedPermanently) diff --git a/errdefs/http_helpers.go b/errdefs/http_helpers.go index 0a8fadd48f..53c18f2fe0 100644 --- a/errdefs/http_helpers.go +++ b/errdefs/http_helpers.go @@ -33,12 +33,12 @@ func FromStatusCode(err error, statusCode int) error { return System(err) default: switch { - case statusCode >= 200 && statusCode < 400: + case statusCode >= http.StatusOK && statusCode < http.StatusBadRequest: // it's a client error return err - case statusCode >= 400 && statusCode < 500: + case statusCode >= http.StatusBadRequest && statusCode < http.StatusInternalServerError: return InvalidParameter(err) - case statusCode >= 500 && statusCode < 600: + case statusCode >= http.StatusInternalServerError && statusCode < 600: return System(err) default: return Unknown(err) diff --git a/integration-cli/docker_cli_external_volume_driver_test.go b/integration-cli/docker_cli_external_volume_driver_test.go index 1a7dafcbbb..cf2a447a1e 100644 --- a/integration-cli/docker_cli_external_volume_driver_test.go +++ b/integration-cli/docker_cli_external_volume_driver_test.go @@ -107,7 +107,7 @@ func newVolumePlugin(t *testing.T, name string) *volumePlugin { send := func(w http.ResponseWriter, data interface{}) { switch d := data.(type) { case error: - http.Error(w, d.Error(), 500) + http.Error(w, d.Error(), http.StatusInternalServerError) case string: w.Header().Set("Content-Type", plugins.VersionMimetype) _, _ = fmt.Fprintln(w, d) diff --git a/integration-cli/docker_cli_registry_user_agent_test.go b/integration-cli/docker_cli_registry_user_agent_test.go index f83d98f4d0..9e6ea59a17 100644 --- a/integration-cli/docker_cli_registry_user_agent_test.go +++ b/integration-cli/docker_cli_registry_user_agent_test.go @@ -55,7 +55,7 @@ func regexpCheckUA(c *testing.T, ua string) { // with the request. func registerUserAgentHandler(reg *registry.Mock, result *string) { reg.RegisterHandler("/v2/", func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(404) + w.WriteHeader(http.StatusNotFound) w.Write([]byte(`{"errors":[{"code": "UNSUPPORTED","message": "this is a mock registry"}]}`)) var ua string for k, v := range r.Header { diff --git a/integration-cli/docker_cli_v2_only_test.go b/integration-cli/docker_cli_v2_only_test.go index 5620350fa6..59ce1cac6f 100644 --- a/integration-cli/docker_cli_v2_only_test.go +++ b/integration-cli/docker_cli_v2_only_test.go @@ -30,7 +30,7 @@ func (s *DockerRegistrySuite) TestV2Only(c *testing.T) { defer reg.Close() reg.RegisterHandler("/v2/", func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(404) + w.WriteHeader(http.StatusNotFound) }) reg.RegisterHandler("/v1/.*", func(w http.ResponseWriter, r *http.Request) { diff --git a/libnetwork/drivers/windows/overlay/ov_endpoint_windows.go b/libnetwork/drivers/windows/overlay/ov_endpoint_windows.go index 05a95bccff..65a09f3a27 100644 --- a/libnetwork/drivers/windows/overlay/ov_endpoint_windows.go +++ b/libnetwork/drivers/windows/overlay/ov_endpoint_windows.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "net" + "net/http" "github.com/Microsoft/hcsshim" "github.com/containerd/log" @@ -77,7 +78,7 @@ func (n *network) removeEndpointWithAddress(addr *net.IPNet) { if networkEndpoint != nil { log.G(context.TODO()).Debugf("Removing stale endpoint from HNS") - _, err := hcsshim.HNSEndpointRequest("DELETE", networkEndpoint.profileID, "") + _, err := hcsshim.HNSEndpointRequest(http.MethodDelete, networkEndpoint.profileID, "") if err != nil { log.G(context.TODO()).Debugf("Failed to delete stale overlay endpoint (%.7s) from hns", networkEndpoint.id) } @@ -99,7 +100,7 @@ func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo dri if ep != nil { log.G(ctx).Debugf("Deleting stale endpoint %s", eid) n.deleteEndpoint(eid) - _, err := hcsshim.HNSEndpointRequest("DELETE", ep.profileID, "") + _, err := hcsshim.HNSEndpointRequest(http.MethodDelete, ep.profileID, "") if err != nil { return err } @@ -182,7 +183,7 @@ func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo dri return err } - hnsresponse, err := hcsshim.HNSEndpointRequest("POST", "", string(configurationb)) + hnsresponse, err := hcsshim.HNSEndpointRequest(http.MethodPost, "", string(configurationb)) if err != nil { return err } @@ -202,7 +203,7 @@ func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo dri ep.portMapping, err = windows.ParsePortBindingPolicies(hnsresponse.Policies) if err != nil { - hcsshim.HNSEndpointRequest("DELETE", hnsresponse.Id, "") + hcsshim.HNSEndpointRequest(http.MethodDelete, hnsresponse.Id, "") return err } @@ -230,7 +231,7 @@ func (d *driver) DeleteEndpoint(nid, eid string) error { n.deleteEndpoint(eid) - _, err := hcsshim.HNSEndpointRequest("DELETE", ep.profileID, "") + _, err := hcsshim.HNSEndpointRequest(http.MethodDelete, ep.profileID, "") if err != nil { return err } diff --git a/libnetwork/drivers/windows/overlay/ov_network_windows.go b/libnetwork/drivers/windows/overlay/ov_network_windows.go index e4b7354b4d..8d606a248c 100644 --- a/libnetwork/drivers/windows/overlay/ov_network_windows.go +++ b/libnetwork/drivers/windows/overlay/ov_network_windows.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "net" + "net/http" "strconv" "strings" "sync" @@ -201,7 +202,7 @@ func (d *driver) DeleteNetwork(nid string) error { return types.ForbiddenErrorf("could not find network with id %s", nid) } - _, err := hcsshim.HNSNetworkRequest("DELETE", n.hnsID, "") + _, err := hcsshim.HNSNetworkRequest(http.MethodDelete, n.hnsID, "") if err != nil { return types.ForbiddenErrorf("%v", err) } @@ -240,7 +241,7 @@ func (d *driver) network(nid string) *network { // func (n *network) restoreNetworkEndpoints() error { // log.G(ctx).Infof("Restoring endpoints for overlay network: %s", n.id) -// hnsresponse, err := hcsshim.HNSListEndpointRequest("GET", "", "") +// hnsresponse, err := hcsshim.HNSListEndpointRequest(http.MethodGet, "", "") // if err != nil { // return err // } @@ -323,7 +324,7 @@ func (d *driver) createHnsNetwork(n *network) error { configuration := string(configurationb) log.G(context.TODO()).Infof("HNSNetwork Request =%v", configuration) - hnsresponse, err := hcsshim.HNSNetworkRequest("POST", "", configuration) + hnsresponse, err := hcsshim.HNSNetworkRequest(http.MethodPost, "", configuration) if err != nil { return err } diff --git a/libnetwork/drivers/windows/overlay/overlay_windows.go b/libnetwork/drivers/windows/overlay/overlay_windows.go index fa737edcd0..3cf9220e36 100644 --- a/libnetwork/drivers/windows/overlay/overlay_windows.go +++ b/libnetwork/drivers/windows/overlay/overlay_windows.go @@ -6,6 +6,7 @@ import ( "context" "encoding/json" "net" + "net/http" "sync" "github.com/Microsoft/hcsshim" @@ -40,7 +41,7 @@ func Register(r driverapi.Registerer) error { func (d *driver) restoreHNSNetworks() error { log.G(context.TODO()).Infof("Restoring existing overlay networks from HNS into docker") - hnsresponse, err := hcsshim.HNSListNetworkRequest("GET", "", "") + hnsresponse, err := hcsshim.HNSListNetworkRequest(http.MethodGet, "", "") if err != nil { return err } diff --git a/libnetwork/drivers/windows/overlay/peerdb_windows.go b/libnetwork/drivers/windows/overlay/peerdb_windows.go index 6708dbc317..0111a37ef5 100644 --- a/libnetwork/drivers/windows/overlay/peerdb_windows.go +++ b/libnetwork/drivers/windows/overlay/peerdb_windows.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "net" + "net/http" "github.com/Microsoft/hcsshim" "github.com/containerd/log" @@ -63,7 +64,7 @@ func (d *driver) peerAdd(nid, eid string, peerIP net.IP, peerIPMask net.IPMask, } n.removeEndpointWithAddress(addr) - hnsresponse, err := hcsshim.HNSEndpointRequest("POST", "", string(configurationb)) + hnsresponse, err := hcsshim.HNSEndpointRequest(http.MethodPost, "", string(configurationb)) if err != nil { return err } @@ -101,7 +102,7 @@ func (d *driver) peerDelete(nid, eid string, peerIP net.IP, peerIPMask net.IPMas } if updateDb { - _, err := hcsshim.HNSEndpointRequest("DELETE", ep.profileID, "") + _, err := hcsshim.HNSEndpointRequest(http.MethodDelete, ep.profileID, "") if err != nil { return err } diff --git a/libnetwork/drivers/windows/windows.go b/libnetwork/drivers/windows/windows.go index 83bf10c011..9d7da205d2 100644 --- a/libnetwork/drivers/windows/windows.go +++ b/libnetwork/drivers/windows/windows.go @@ -16,6 +16,7 @@ import ( "encoding/json" "fmt" "net" + "net/http" "strconv" "strings" "sync" @@ -373,7 +374,7 @@ func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string configuration := string(configurationb) log.G(ctx).Debugf("HNSNetwork Request =%v Address Space=%v", configuration, subnets) - hnsresponse, err := hcsshim.HNSNetworkRequest("POST", "", configuration) + hnsresponse, err := hcsshim.HNSNetworkRequest(http.MethodPost, "", configuration) if err != nil { return err } @@ -417,7 +418,7 @@ func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string for _, ep := range endpoints { if ep.VirtualNetwork == config.HnsID { log.G(ctx).Infof("Removing stale HNS endpoint %s", ep.Id) - _, err = hcsshim.HNSEndpointRequest("DELETE", ep.Id, "") + _, err = hcsshim.HNSEndpointRequest(http.MethodDelete, ep.Id, "") if err != nil { log.G(ctx).Warnf("Error removing HNS endpoint %s", ep.Id) } @@ -444,7 +445,7 @@ func (d *driver) DeleteNetwork(nid string) error { n.Unlock() if n.created { - _, err = hcsshim.HNSNetworkRequest("DELETE", config.HnsID, "") + _, err = hcsshim.HNSNetworkRequest(http.MethodDelete, config.HnsID, "") if err != nil && !strings.EqualFold(err.Error(), errNotFound) { return types.ForbiddenErrorf("%v", err) } @@ -723,7 +724,7 @@ func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo dri return err } - hnsresponse, err := hcsshim.HNSEndpointRequest("POST", "", string(configurationb)) + hnsresponse, err := hcsshim.HNSEndpointRequest(http.MethodPost, "", string(configurationb)) if err != nil { return err } @@ -751,7 +752,7 @@ func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo dri endpoint.epOption = epOption endpoint.portMapping, err = ParsePortBindingPolicies(hnsresponse.Policies) if err != nil { - hcsshim.HNSEndpointRequest("DELETE", hnsresponse.Id, "") + hcsshim.HNSEndpointRequest(http.MethodDelete, hnsresponse.Id, "") return err } @@ -793,7 +794,7 @@ func (d *driver) DeleteEndpoint(nid, eid string) error { delete(n.endpoints, eid) n.Unlock() - _, err = hcsshim.HNSEndpointRequest("DELETE", ep.profileID, "") + _, err = hcsshim.HNSEndpointRequest(http.MethodDelete, ep.profileID, "") if err != nil && !strings.EqualFold(err.Error(), errNotFound) { return err } diff --git a/libnetwork/network_windows.go b/libnetwork/network_windows.go index 2e3375d4a8..2e140dfaca 100644 --- a/libnetwork/network_windows.go +++ b/libnetwork/network_windows.go @@ -6,6 +6,7 @@ import ( "context" "fmt" "net" + "net/http" "net/netip" "runtime" "strings" @@ -55,7 +56,7 @@ func (n *Network) startResolver() { return } - hnsresponse, err := hcsshim.HNSNetworkRequest("GET", hnsid, "") + hnsresponse, err := hcsshim.HNSNetworkRequest(http.MethodGet, hnsid, "") if err != nil { log.G(context.TODO()).Errorf("Resolver Setup/Start failed for container %s, %q", n.Name(), err) return diff --git a/volume/drivers/proxy_test.go b/volume/drivers/proxy_test.go index 7fef62f2dc..c6b3bcf747 100644 --- a/volume/drivers/proxy_test.go +++ b/volume/drivers/proxy_test.go @@ -54,7 +54,7 @@ func TestVolumeRequestError(t *testing.T) { mux.HandleFunc("/VolumeDriver.Capabilities", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", plugins.VersionMimetype) - http.Error(w, "error", 500) + http.Error(w, "error", http.StatusInternalServerError) }) u, _ := url.Parse(server.URL)