diff --git a/.golangci.yml b/.golangci.yml index 6ff842d8..524fc7f8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -30,7 +30,7 @@ linters: - gofmt - gofumpt - goimports - - golint + - revive - gosec - makezero - misspell diff --git a/metadata/metadata.go b/metadata/metadata.go index 4d82b11f..219e94ba 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -107,13 +107,16 @@ func New(size int) Metadata { // Merge merges metadata to existing metadata, overwriting if specified func Merge(omd Metadata, mmd Metadata, overwrite bool) Metadata { + var ok bool nmd := Copy(omd) for key, val := range mmd { - if _, ok := nmd[key]; ok && !overwrite { - // skip - } else if val != "" { + _, ok = nmd[key] + switch { + case ok && !overwrite: + continue + case val != "": nmd.Set(key, val) - } else { + case ok && val == "": nmd.Del(key) } } diff --git a/util/http/trie_test.go b/util/http/trie_test.go index c6cfc95c..be48fd78 100644 --- a/util/http/trie_test.go +++ b/util/http/trie_test.go @@ -41,11 +41,12 @@ func TestTrieMatchRegexp(t *testing.T) { tr.Insert([]string{http.MethodPut}, "/v1/create/{category}/{id:[0-9]+}", &handler{}) _, params, ok := tr.Search(http.MethodPut, "/v1/create/test_cat/12345") - if !ok { + switch { + case !ok: t.Fatalf("route not found") - } else if len(params) != 2 { + case len(params) != 2: t.Fatalf("param matching error %v", params) - } else if params["category"] != "test_cat" { + case params["category"] != "test_cat": t.Fatalf("param matching error %v", params) } }