From c089b35b09d6e2f069b5ee65e183fbc9082614d4 Mon Sep 17 00:00:00 2001 From: zhulh200868 <3205777381@qq.com> Date: Sun, 24 Dec 2017 20:25:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E5=A2=9E=E5=8A=A0nodata=E7=9A=84?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8Cendpoint?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E8=BF=99=E5=9D=97=E4=B8=8B=E9=9D=A2=E5=A1=AB?= =?UTF-8?q?=E5=86=99group=E7=9A=84=E6=97=B6=E5=80=99=E5=8F=AA=E8=83=BD?= =?UTF-8?q?=E5=86=99=E4=B8=80=E5=88=97=E4=B8=8B=E5=A4=9A=E8=A1=8C=E8=80=8C?= =?UTF-8?q?=E4=B8=94=E8=A1=8C=E6=95=B0=E6=9C=89=E9=99=90=E5=88=B6=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=94=B9=E6=88=90=E9=80=97=E5=8F=B7=E5=88=86?= =?UTF-8?q?=E5=89=B2=E7=9A=84=E8=AF=9D=E5=B0=B1=E5=A4=9A=E4=BA=86=E3=80=82?= =?UTF-8?q?=E5=9B=A0=E4=B8=BA=E5=AF=B9mockcfg.go=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E9=80=97=E5=8F=B7=E5=88=86=E5=89=B2group=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/nodata/config/service/mockcfg.go | 31 ++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/modules/nodata/config/service/mockcfg.go b/modules/nodata/config/service/mockcfg.go index 86c288d01..58a8f0d51 100644 --- a/modules/nodata/config/service/mockcfg.go +++ b/modules/nodata/config/service/mockcfg.go @@ -35,6 +35,16 @@ type MockCfg struct { Mock float64 } +//增加struct +type MyStruct struct { + grplist []string + hostlist []string + otherlist []string +} + +//定义一个groups +var mystruct MyStruct + // 当 grp展开结果 与 host结果 存在冲突时, 优先选择 host结果 func GetMockCfgFromDB() map[string]*cmodel.NodataConfig { ret := make(map[string]*cmodel.NodataConfig) @@ -70,6 +80,7 @@ func GetMockCfgFromDB() map[string]*cmodel.NodataConfig { } endpoints := getEndpoint(t.ObjType, t.Obj) + //log.Println("The endpoints is ",endpoints) if len(endpoints) < 1 { continue } @@ -113,7 +124,15 @@ func getEndpoint(objType string, obj string) []string { func getEndpointFromHosts(hosts string) []string { ret := make([]string, 0) - hlist := strings.Split(hosts, "\n") + //hlist := strings.Split(hosts, "\n") + //在这里判断分隔符是"\n"还是"," + if strings.Contains(hosts, "\n") { + mystruct.hostlist = strings.Split(hosts, "\n") + } else if strings.Contains(hosts, ",") { + mystruct.hostlist = strings.Split(hosts, ",") + } + hlist := mystruct.hostlist + for _, host := range hlist { nh := strings.TrimSpace(host) if nh != "" { @@ -125,7 +144,15 @@ func getEndpointFromHosts(hosts string) []string { } func getEndpointFromGroups(grps string) []string { - grplist := strings.Split(grps, "\n") + //在这里判断分隔符是"\n"还是"," + if strings.Contains(grps, "\n") { + mystruct.grplist = strings.Split(grps, "\n") + } else if strings.Contains(grps, ",") { + mystruct.grplist = strings.Split(grps, ",") + } + grplist := mystruct.grplist + //grplist := strings.Split(grps, ",") + //grplist := strings.Split(grps, "\n") // get host map, avoid duplicating hosts := make(map[string]string)