github.com/xmidt-org/webpa-common@v1.11.9/xhttp/xcontext/setClient.go (about)

     1  package xcontext
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  
     7  	gokithttp "github.com/go-kit/kit/transport/http"
     8  	"github.com/xmidt-org/webpa-common/xhttp"
     9  )
    10  
    11  // SetClient is a ContextFunc strategy that injects a supplied HTTP client into the HTTP context.
    12  // Very useful when an outbound HTTP call needs to be made in response to a server request.
    13  func SetClient(c xhttp.Client) gokithttp.RequestFunc {
    14  	return func(ctx context.Context, _ *http.Request) context.Context {
    15  		return xhttp.WithClient(ctx, c)
    16  	}
    17  }