Пример #1
0
// New returns an AddService that's backed by the URL. baseurl will have its
// scheme and hostport used, but its path will be overwritten. If client is
// nil, http.DefaultClient will be used.
func New(ctx context.Context, baseurl *url.URL, logger log.Logger, c *http.Client) server.AddService {
	sumURL, err := url.Parse(baseurl.String())
	if err != nil {
		panic(err)
	}
	sumURL.Path = "/sum"

	concatURL, err := url.Parse(baseurl.String())
	if err != nil {
		panic(err)
	}
	concatURL.Path = "/concat"

	return client{
		Context: ctx,
		Logger:  logger,
		sum: httptransport.NewClient(
			"GET",
			sumURL,
			server.EncodeSumRequest,
			server.DecodeSumResponse,
			httptransport.SetClient(c),
		).Endpoint(),
		concat: httptransport.NewClient(
			"GET",
			concatURL,
			server.EncodeConcatRequest,
			server.DecodeConcatResponse,
			httptransport.SetClient(c),
		).Endpoint(),
	}
}
Пример #2
0
// ConcatEndpointFactory transforms a http url into an Endpoint.
// The path of the url is reset to /concat.
func ConcatEndpointFactory(instance string) (endpoint.Endpoint, io.Closer, error) {
	concatURL, err := url.Parse(instance)
	if err != nil {
		return nil, nil, err
	}
	concatURL.Path = "/concat"

	client := httptransport.NewClient(
		"GET",
		concatURL,
		server.EncodeConcatRequest,
		server.DecodeConcatResponse,
		httptransport.SetClient(nil),
	)

	return client.Endpoint(), nil, nil
}
Пример #3
0
// SumEndpointFactory transforms a http url into an Endpoint.
// The path of the url is reset to /sum.
func SumEndpointFactory(instance string) (endpoint.Endpoint, io.Closer, error) {
	sumURL, err := url.Parse(instance)
	if err != nil {
		return nil, nil, err
	}
	sumURL.Path = "/sum"

	client := httptransport.NewClient(
		"GET",
		sumURL,
		server.EncodeSumRequest,
		server.DecodeSumResponse,
		httptransport.SetClient(nil),
	)

	return client.Endpoint(), nil, nil
}
Пример #4
0
// MakeConcatEndpointFactory generates a Factory that transforms an http url
// into an Endpoint.
//
// The path of the url is reset to /concat.
func MakeConcatEndpointFactory(tracer opentracing.Tracer, tracingLogger log.Logger) loadbalancer.Factory {
	return func(instance string) (endpoint.Endpoint, io.Closer, error) {
		concatURL, err := url.Parse(instance)
		if err != nil {
			return nil, nil, err
		}
		concatURL.Path = "/concat"

		client := httptransport.NewClient(
			"GET",
			concatURL,
			server.EncodeConcatRequest,
			server.DecodeConcatResponse,
			httptransport.SetClient(nil),
			httptransport.SetClientBefore(kitot.ToHTTPRequest(tracer, tracingLogger)),
		)

		return client.Endpoint(), nil, nil
	}
}