From d778d034e75d3d0f4e3e326404c2e1dd04032b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=9E=E9=9B=AA=E6=97=A0=E6=83=85?= Date: Thu, 24 Sep 2020 23:40:21 +0800 Subject: [PATCH] Remove redundant mgmtQueryKey type. (#10557) Remove redundant type conversion. --- cmd/admin-handlers.go | 25 +++++++++++-------------- cmd/admin-handlers_test.go | 12 ++++++------ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index 26e6367da..b3298a286 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -54,16 +54,13 @@ const ( maxEConfigJSONSize = 262272 ) -// Type-safe query params. -type mgmtQueryKey string - // Only valid query params for mgmt admin APIs. const ( - mgmtBucket mgmtQueryKey = "bucket" - mgmtPrefix = "prefix" - mgmtClientToken = "clientToken" - mgmtForceStart = "forceStart" - mgmtForceStop = "forceStop" + mgmtBucket = "bucket" + mgmtPrefix = "prefix" + mgmtClientToken = "clientToken" + mgmtForceStart = "forceStart" + mgmtForceStop = "forceStop" ) func updateServer(u *url.URL, sha256Sum []byte, lrTime time.Time, mode string) (us madmin.ServerUpdateStatus, err error) { @@ -572,8 +569,8 @@ type healInitParams struct { // extractHealInitParams - Validates params for heal init API. func extractHealInitParams(vars map[string]string, qParms url.Values, r io.Reader) (hip healInitParams, err APIErrorCode) { - hip.bucket = vars[string(mgmtBucket)] - hip.objPrefix = vars[string(mgmtPrefix)] + hip.bucket = vars[mgmtBucket] + hip.objPrefix = vars[mgmtPrefix] if hip.bucket == "" { if hip.objPrefix != "" { @@ -592,13 +589,13 @@ func extractHealInitParams(vars map[string]string, qParms url.Values, r io.Reade return } - if len(qParms[string(mgmtClientToken)]) > 0 { - hip.clientToken = qParms[string(mgmtClientToken)][0] + if len(qParms[mgmtClientToken]) > 0 { + hip.clientToken = qParms[mgmtClientToken][0] } - if _, ok := qParms[string(mgmtForceStart)]; ok { + if _, ok := qParms[mgmtForceStart]; ok { hip.forceStart = true } - if _, ok := qParms[string(mgmtForceStop)]; ok { + if _, ok := qParms[mgmtForceStop]; ok { hip.forceStop = true } diff --git a/cmd/admin-handlers_test.go b/cmd/admin-handlers_test.go index c00a0bc9a..e7b56478c 100644 --- a/cmd/admin-handlers_test.go +++ b/cmd/admin-handlers_test.go @@ -327,13 +327,13 @@ func TestExtractHealInitParams(t *testing.T) { mkParams := func(clientToken string, forceStart, forceStop bool) url.Values { v := url.Values{} if clientToken != "" { - v.Add(string(mgmtClientToken), clientToken) + v.Add(mgmtClientToken, clientToken) } if forceStart { - v.Add(string(mgmtForceStart), "") + v.Add(mgmtForceStart, "") } if forceStop { - v.Add(string(mgmtForceStop), "") + v.Add(mgmtForceStop, "") } return v } @@ -351,11 +351,11 @@ func TestExtractHealInitParams(t *testing.T) { } varsArr := []map[string]string{ // Invalid cases - {string(mgmtPrefix): "objprefix"}, + {mgmtPrefix: "objprefix"}, // Valid cases {}, - {string(mgmtBucket): "bucket"}, - {string(mgmtBucket): "bucket", string(mgmtPrefix): "objprefix"}, + {mgmtBucket: "bucket"}, + {mgmtBucket: "bucket", mgmtPrefix: "objprefix"}, } // Body is always valid - we do not test JSON decoding.