mirror of
https://github.com/IBM/fp-go.git
synced 2025-08-10 22:31:32 +02:00
fix: linter bugs
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@@ -24,9 +24,9 @@ import (
|
||||
F "github.com/IBM/fp-go/function"
|
||||
)
|
||||
|
||||
// LogJson converts the argument to JSON and then logs it via the format string
|
||||
// LogJSON converts the argument to JSON and then logs it via the format string
|
||||
// Can be used with [ChainFirst]
|
||||
func LogJson[GA ~func() ET.Either[error, any], A any](prefix string) func(A) GA {
|
||||
func LogJSON[GA ~func() ET.Either[error, any], A any](prefix string) func(A) GA {
|
||||
return func(a A) GA {
|
||||
// log this
|
||||
return F.Pipe3(
|
||||
@@ -41,3 +41,11 @@ func LogJson[GA ~func() ET.Either[error, any], A any](prefix string) func(A) GA
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// LogJson converts the argument to JSON and then logs it via the format string
|
||||
// Can be used with [ChainFirst]
|
||||
//
|
||||
// Deprecated: use [LogJSON] instead
|
||||
func LogJson[GA ~func() ET.Either[error, any], A any](prefix string) func(A) GA {
|
||||
return LogJSON[GA, A](prefix)
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ func Requester(builder *R.Builder) IOEH.Requester {
|
||||
return F.Pipe5(
|
||||
builder.GetBody(),
|
||||
O.Fold(LZ.Of(E.Of[error](withoutBody)), E.Map[error](withBody)),
|
||||
E.Ap[func(string) IOE.IOEither[error, *http.Request]](builder.GetTargetUrl()),
|
||||
E.Ap[func(string) IOE.IOEither[error, *http.Request]](builder.GetTargetURL()),
|
||||
E.Flap[error, IOE.IOEither[error, *http.Request]](builder.GetMethod()),
|
||||
E.GetOrElse(IOE.Left[*http.Request, error]),
|
||||
IOE.Map[error](func(req *http.Request) *http.Request {
|
||||
|
@@ -118,12 +118,19 @@ func ReadText(client Client) func(Requester) IOE.IOEither[error, string] {
|
||||
}
|
||||
|
||||
// ReadJson sends a request, reads the response and parses the response as JSON
|
||||
//
|
||||
// Deprecated: use [ReadJSON] instead
|
||||
func ReadJson[A any](client Client) func(Requester) IOE.IOEither[error, A] {
|
||||
return ReadJSON[A](client)
|
||||
}
|
||||
|
||||
// ReadJSON sends a request, reads the response and parses the response as JSON
|
||||
func ReadJSON[A any](client Client) func(Requester) IOE.IOEither[error, A] {
|
||||
return F.Flow3(
|
||||
ReadFullResponse(client),
|
||||
IOE.ChainFirstEitherK(F.Flow2(
|
||||
H.Response,
|
||||
H.ValidateJsonResponse,
|
||||
H.ValidateJSONResponse,
|
||||
)),
|
||||
IOE.ChainEitherK(F.Flow2(
|
||||
H.Body,
|
||||
|
@@ -54,7 +54,7 @@ func TestRetryHttp(t *testing.T) {
|
||||
action := func(status R.RetryStatus) IOE.IOEither[error, *PostItem] {
|
||||
return F.Pipe1(
|
||||
MakeGetRequest(urls[status.IterNumber]),
|
||||
ReadJson[*PostItem](client),
|
||||
ReadJSON[*PostItem](client),
|
||||
)
|
||||
}
|
||||
|
||||
|
@@ -21,6 +21,14 @@ import (
|
||||
|
||||
// LogJson converts the argument to pretty printed JSON and then logs it via the format string
|
||||
// Can be used with [ChainFirst]
|
||||
//
|
||||
// Deprecated: use [LogJSON] instead
|
||||
func LogJson[A any](prefix string) func(A) IOEither[error, any] {
|
||||
return G.LogJson[IOEither[error, any], A](prefix)
|
||||
}
|
||||
|
||||
// LogJSON converts the argument to pretty printed JSON and then logs it via the format string
|
||||
// Can be used with [ChainFirst]
|
||||
func LogJSON[A any](prefix string) func(A) IOEither[error, any] {
|
||||
return G.LogJSON[IOEither[error, any], A](prefix)
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ func TestLogging(t *testing.T) {
|
||||
|
||||
res := F.Pipe1(
|
||||
Of[error](src),
|
||||
ChainFirst(LogJson[*SomeData]("Data: \n%s")),
|
||||
ChainFirst(LogJSON[*SomeData]("Data: \n%s")),
|
||||
)
|
||||
|
||||
dst := res()
|
||||
|
Reference in New Issue
Block a user