Builder and Bridge Build takes a slice of async, sync middleware and a http.RoundTripper and builds a request pipeline
(asyncMW []AsyncMiddleware[combiner.PipelineResponse], mw []Middleware, next RoundTripper)
| 149 | |
| 150 | // Build takes a slice of async, sync middleware and a http.RoundTripper and builds a request pipeline |
| 151 | func Build(asyncMW []AsyncMiddleware[combiner.PipelineResponse], mw []Middleware, next RoundTripper) AsyncRoundTripper[combiner.PipelineResponse] { |
| 152 | asyncPipeline := AsyncMiddlewareFunc[combiner.PipelineResponse](func(next AsyncRoundTripper[combiner.PipelineResponse]) AsyncRoundTripper[combiner.PipelineResponse] { |
| 153 | for i := len(asyncMW) - 1; i >= 0; i-- { |
| 154 | next = asyncMW[i].Wrap(next) |
| 155 | } |
| 156 | return next |
| 157 | }) |
| 158 | |
| 159 | syncPipeline := MiddlewareFunc(func(next RoundTripper) RoundTripper { |
| 160 | for i := len(mw) - 1; i >= 0; i-- { |
| 161 | next = mw[i].Wrap(next) |
| 162 | } |
| 163 | return next |
| 164 | }) |
| 165 | |
| 166 | // bridge the two pipelines |
| 167 | bridge := &pipelineBridge{ |
| 168 | next: syncPipeline.Wrap(RoundTripperFunc(func(req Request) (*http.Response, error) { |
| 169 | return next.RoundTrip(req) |
| 170 | })), |
| 171 | convert: NewHTTPToAsyncResponse, |
| 172 | } |
| 173 | return asyncPipeline.Wrap(bridge) |
| 174 | } |
| 175 | |
| 176 | var _ AsyncRoundTripper[combiner.PipelineResponse] = (*pipelineBridge)(nil) |
| 177 |
no test coverage detected