mirror of
https://github.com/IBM/fp-go.git
synced 2025-08-10 22:31:32 +02:00
fix: add MakeBodyRequest
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@@ -16,10 +16,12 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
B "github.com/IBM/fp-go/bytes"
|
||||
FL "github.com/IBM/fp-go/file"
|
||||
F "github.com/IBM/fp-go/function"
|
||||
H "github.com/IBM/fp-go/http"
|
||||
IOE "github.com/IBM/fp-go/ioeither"
|
||||
@@ -51,6 +53,24 @@ var (
|
||||
MakeGetRequest = makeRequest("GET", nil)
|
||||
)
|
||||
|
||||
// MakeBodyRequest creates a request that carries a body
|
||||
func MakeBodyRequest(method string, body IOE.IOEither[error, []byte]) func(url string) IOE.IOEither[error, *http.Request] {
|
||||
onBody := F.Pipe1(
|
||||
body,
|
||||
IOE.Map[error](F.Flow2(
|
||||
bytes.NewReader,
|
||||
FL.ToReader[*bytes.Reader],
|
||||
)),
|
||||
)
|
||||
onRelease := IOE.Of[error, io.Reader]
|
||||
withMethod := F.Bind1of3(MakeRequest)(method)
|
||||
|
||||
return F.Flow2(
|
||||
F.Bind1of2(withMethod),
|
||||
IOE.WithResource[*http.Request](onBody, onRelease),
|
||||
)
|
||||
}
|
||||
|
||||
func (client client) Do(req Requester) IOE.IOEither[error, *http.Response] {
|
||||
return F.Pipe1(
|
||||
req,
|
||||
|
Reference in New Issue
Block a user