Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nodata的endpoint选择的逗号分割 #317

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions modules/nodata/config/service/mockcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 != "" {
Expand All @@ -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)
Expand Down