-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from ozontech/release/v0.1.11
[v0.1.11] Implement query builder, implement require validations
- Loading branch information
Showing
19 changed files
with
480 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cute | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/ozontech/cute/errors" | ||
) | ||
|
||
func optionalAssertHeaders(assert AssertHeaders) AssertHeaders { | ||
return func(headers http.Header) error { | ||
err := assert(headers) | ||
|
||
return wrapOptionalError(err) | ||
} | ||
} | ||
|
||
func optionalAssertBody(assert AssertBody) AssertBody { | ||
return func(body []byte) error { | ||
err := assert(body) | ||
|
||
return wrapOptionalError(err) | ||
} | ||
} | ||
|
||
func optionalAssertResponse(assert AssertResponse) AssertResponse { | ||
return func(resp *http.Response) error { | ||
err := assert(resp) | ||
|
||
return wrapOptionalError(err) | ||
} | ||
} | ||
|
||
func optionalAssertHeadersT(assert AssertHeadersT) AssertHeadersT { | ||
return func(t T, headers http.Header) error { | ||
err := assert(t, headers) | ||
|
||
return wrapOptionalError(err) | ||
} | ||
} | ||
|
||
func optionalAssertBodyT(assert AssertBodyT) AssertBodyT { | ||
return func(t T, body []byte) error { | ||
err := assert(t, body) | ||
|
||
return wrapOptionalError(err) | ||
} | ||
} | ||
|
||
func optionalAssertResponseT(assert AssertResponseT) AssertResponseT { | ||
return func(t T, resp *http.Response) error { | ||
err := assert(t, resp) | ||
|
||
return wrapOptionalError(err) | ||
} | ||
} | ||
|
||
func wrapOptionalError(err error) error { | ||
if err == nil { | ||
return nil | ||
} | ||
|
||
if tErr, ok := err.(errors.OptionalError); ok { | ||
tErr.SetOptional(true) | ||
|
||
return tErr.(error) | ||
} | ||
|
||
return errors.NewOptionalError(err.Error()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cute | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/ozontech/cute/errors" | ||
) | ||
|
||
func requireAssertHeaders(assert AssertHeaders) AssertHeaders { | ||
return func(headers http.Header) error { | ||
err := assert(headers) | ||
|
||
return wrapRequireError(err) | ||
} | ||
} | ||
|
||
func requireAssertBody(assert AssertBody) AssertBody { | ||
return func(body []byte) error { | ||
err := assert(body) | ||
|
||
return wrapRequireError(err) | ||
} | ||
} | ||
|
||
func requireAssertResponse(assert AssertResponse) AssertResponse { | ||
return func(resp *http.Response) error { | ||
err := assert(resp) | ||
|
||
return wrapRequireError(err) | ||
} | ||
} | ||
|
||
func requireAssertHeadersT(assert AssertHeadersT) AssertHeadersT { | ||
return func(t T, headers http.Header) error { | ||
err := assert(t, headers) | ||
|
||
return wrapRequireError(err) | ||
} | ||
} | ||
|
||
func requireAssertBodyT(assert AssertBodyT) AssertBodyT { | ||
return func(t T, body []byte) error { | ||
err := assert(t, body) | ||
|
||
return wrapRequireError(err) | ||
} | ||
} | ||
|
||
func requireAssertResponseT(assert AssertResponseT) AssertResponseT { | ||
return func(t T, resp *http.Response) error { | ||
err := assert(t, resp) | ||
|
||
return wrapRequireError(err) | ||
} | ||
} | ||
|
||
func wrapRequireError(err error) error { | ||
if err == nil { | ||
return nil | ||
} | ||
|
||
if tErr, ok := err.(errors.RequireError); ok { | ||
tErr.SetRequire(true) | ||
|
||
return tErr.(error) | ||
} | ||
|
||
return errors.NewRequireError(err.Error()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.