示例#1
0
文件: http.go 项目: lifey/consult
func printHttp(x *httpReqResp) {
	fmt.Printf("* Connect: %s:%d\n", x.host, x.port)
	if b, err := httputil.DumpRequestOut(x.req, false); err == nil {
		stream.FromArray(strings.Split(string(b), "\n")).Each(func(l string) {
			fmt.Println("> " + l)
		})
	}
	if b, err := httputil.DumpResponse(x.resp, true); err == nil {
		stream.FromArray(strings.Split(string(b), "\n")).Each(func(l string) {
			fmt.Println("< " + l)
		})
	}
}
示例#2
0
文件: http.go 项目: lifey/consult
func httpExecute(endpoints []*api.CatalogService,
	method string,
	scheme string,
	uri string,
	body string,
	headers map[string]string,
) {
	(&basePStream{stream.FromArray(endpoints)}).PMap(
		func(endpoint interface{}) interface{} {
			return httpCallEndpoint(endpoint.(*api.CatalogService), method, scheme, uri, body, headers)
		},
	).Each(printHttp)
}
示例#3
0
func (v *basePStream) PMap(f stream.MapFunc) stream.Stream {
	futures := make([]interface{}, 0)
	iter := v.Map(func(arg interface{}) interface{} {
		return parallel.MakeFuture(parallel.MapFunc(f), arg)
	}).Iterator()

	for v, ok := iter.Next(); ok; v, ok = iter.Next() {
		futures = append(futures, v)
	}

	return stream.FromArray(futures).Map(func(future interface{}) interface{} {
		return future.(parallel.Future).Wait()
	})
}
示例#4
0
文件: query.go 项目: lifey/consult
func (q *QueryCommand) queryMulti(
	client *api.Client,
	mergeFunc misc.CatalogServicesMerger,
) []*api.CatalogService {
	// handle the case of no tags
	if len(q.tags) == 0 {
		return q.IQuery.Query(client, "")
	}

	res, ok := (&basePStream{stream.FromArray(q.tags)}).PMap(
		func(tag interface{}) interface{} {
			return q.IQuery.Query(client, tag.(string)) // use q.IQuery.Query so we can override for testing
		}).Reduce(mergeFunc).Value()

	if ok {
		return res.([]*api.CatalogService)
	} else {
		// perhaps blow up instead?
		return []*api.CatalogService{}
	}
}