Exemplo n.º 1
0
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)
		})
	}
}
Exemplo n.º 2
0
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)
}
Exemplo n.º 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()
	})
}
Exemplo n.º 4
0
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{}
	}
}