コード例 #1
0
ファイル: services.go プロジェクト: colebrumley/consulctl
func parseCatalogServices(catalog *api.Catalog, qOpts *api.QueryOptions) ([]*api.CatalogService, error) {
	results := []*api.CatalogService{}
	svcs, _, err := catalog.Services(&api.QueryOptions{})
	if err != nil {
		return results, err
	}
	for k, v := range svcs {
		if len(v) > 0 {
			for _, i := range v {
				sInfo, _, err := catalog.Service(k, i, qOpts)
				if err != nil {
					return results, err
				}
				for _, s := range sInfo {
					results = append(results, s)
				}
			}
			continue
		}
		sInfo, _, err := catalog.Service(k, "", qOpts)
		if err != nil {
			return results, err
		}
		for _, s := range sInfo {
			results = append(results, s)
		}
	}
	return results, err
}
コード例 #2
0
func waitForServiceCount(t *testing.T, catalog *consulapi.Catalog, serviceName string, count int) {
	testutil.WaitForResult(func() (bool, error) {
		x, _, err := catalog.Service(serviceName, "", nil)

		if err != nil {
			return false, err
		}

		if len(x) != count {
			return false, errors.New("Wrong service count")
		}

		return true, nil
	}, func(err error) {
		t.Fatal("Error: ", err)
	})
}