From 2f33bf00e2eff393687e116fe3da6b6b9f799102 Mon Sep 17 00:00:00 2001 From: Joe Zou <yixian.zou@gmail.com> Date: Thu, 13 Feb 2020 23:57:44 +0800 Subject: [PATCH] fix review comment --- cluster/router/condition/router_parser.go | 49 ------------------- cluster/router/condition/router_rule.go | 31 ++++++++++++ ...ter_parser_test.go => router_rule_test.go} | 0 3 files changed, 31 insertions(+), 49 deletions(-) delete mode 100644 cluster/router/condition/router_parser.go rename cluster/router/condition/{router_parser_test.go => router_rule_test.go} (100%) diff --git a/cluster/router/condition/router_parser.go b/cluster/router/condition/router_parser.go deleted file mode 100644 index 6e890a9cf..000000000 --- a/cluster/router/condition/router_parser.go +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package condition - -import ( - "gopkg.in/yaml.v2" -) - -/* Parse Router raw rule parser - * example : - * scope: application - * runtime: true - * force: false - * conditions: - * - > - * method!=sayHello => - * - > - * ip=127.0.0.1 - * => - * 1.1.1.1 - */ -func Parse(rawRule string) (*RouterRule, error) { - r := &RouterRule{} - err := yaml.Unmarshal([]byte(rawRule), r) - if err != nil { - return r, err - } - r.RawRule = rawRule - if len(r.Conditions) != 0 { - r.Valid = true - } - - return r, nil -} diff --git a/cluster/router/condition/router_rule.go b/cluster/router/condition/router_rule.go index 1a4fd54a7..1374cf9de 100644 --- a/cluster/router/condition/router_rule.go +++ b/cluster/router/condition/router_rule.go @@ -17,6 +17,10 @@ package condition +import ( + "gopkg.in/yaml.v2" +) + import ( "github.com/apache/dubbo-go/cluster/router" ) @@ -26,3 +30,30 @@ type RouterRule struct { router.BaseRouterRule `yaml:",inline""` Conditions []string } + +/* Parse Router raw rule parser + * example : + * scope: application + * runtime: true + * force: false + * conditions: + * - > + * method!=sayHello => + * - > + * ip=127.0.0.1 + * => + * 1.1.1.1 + */ +func Parse(rawRule string) (*RouterRule, error) { + r := &RouterRule{} + err := yaml.Unmarshal([]byte(rawRule), r) + if err != nil { + return r, err + } + r.RawRule = rawRule + if len(r.Conditions) != 0 { + r.Valid = true + } + + return r, nil +} diff --git a/cluster/router/condition/router_parser_test.go b/cluster/router/condition/router_rule_test.go similarity index 100% rename from cluster/router/condition/router_parser_test.go rename to cluster/router/condition/router_rule_test.go -- GitLab