Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor gitBinaryMaskParam function #2634

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
85404b4
WIP
May 15, 2023
797e72f
WIP
May 15, 2023
c38f586
WIP
May 15, 2023
b920022
WIP
May 15, 2023
e6a5b9a
WIP
May 15, 2023
0222513
WIP
May 15, 2023
9c440cc
Merge branch 'main' into issue-2465-document-params-functions
May 15, 2023
76a67b8
WIP
May 16, 2023
c0d4b22
Merge remote-tracking branch 'origin/issue-2465-document-params-funct…
May 16, 2023
fa3aa04
WIP
May 16, 2023
7dcbf6a
WIP
May 16, 2023
5bdccc2
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 17, 2023
efa129a
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 17, 2023
931f091
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 17, 2023
38dc72b
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 17, 2023
e43473d
Merge branch 'main' into issue-2465-document-params-functions
May 17, 2023
0646a22
Merge branch 'issue-2465-document-params-functions' of https://github…
May 17, 2023
b760653
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 17, 2023
3bbe433
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 17, 2023
df743c8
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 17, 2023
3105a6b
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 18, 2023
95353cb
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 18, 2023
05dd793
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 18, 2023
a04e11d
Merge branch 'main' into issue-2465-document-params-functions
May 22, 2023
aea7ad4
WIP
May 22, 2023
d9f4a21
WIP
May 22, 2023
1f4a61e
WIP
May 22, 2023
ce2eb0d
WIP
May 22, 2023
b04cb3f
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
Dmitry committed May 16, 2023
commit fa3aa0442a3cf82283bed7ebe959cc9a3fcf7471
14 changes: 7 additions & 7 deletions internal/handlers/common/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

// GetRequiredParam returns doc's value for key.
//
// Returned errors:
// It returns command errors with the following codes:
// - ErrBadValue if the document value is missing;
// - ErrBadValue if the document value is not of the expected type.
func GetRequiredParam[T types.Type](doc *types.Document, key string) (T, error) {
Expand All @@ -51,7 +51,7 @@ func GetRequiredParam[T types.Type](doc *types.Document, key string) (T, error)

// GetOptionalParam returns doc's value for key or default value for missing parameter.
//
// ErrTypeMismatch returned if the document value is not of the expected type.
// It returns command error with the ErrTypeMismatch code if the document value is not of the expected type.
func GetOptionalParam[T types.Type](doc *types.Document, key string, defaultValue T) (T, error) {
v, _ := doc.Get(key)
if v == nil {
Expand All @@ -74,7 +74,7 @@ func GetOptionalParam[T types.Type](doc *types.Document, key string, defaultValu

// GetOptionalNullParam returns doc's value for key, default value for missing parameter or null.
//
// ErrTypeMismatch returned if the document value is not of the expected type.
// It returns command error with ErrTypeMismatch code if the document value is not of the expected type.
func GetOptionalNullParam[T types.Type](doc *types.Document, key string, defaultValue T) (T, error) {
v, err := GetOptionalParam(doc, key, defaultValue)
if err != nil {
Expand All @@ -96,7 +96,7 @@ func GetOptionalNullParam[T types.Type](doc *types.Document, key string, default
// return commonerrors.NewCommandErrorMsg(commonerrors.ErrBadValue, "expected document")
// }
//
// ErrBadValue returned if the value is not of the expected type.
// It returns command error with ErrBadValue code if the value is not of the expected type.
func AssertType[T types.Type](value any) (T, error) {
res, ok := value.(T)
if !ok {
Expand All @@ -109,7 +109,7 @@ func AssertType[T types.Type](value any) (T, error) {

// GetLimitStageParam returns $limit stage argument from the provided value.
//
// Returned errors:
// It returns command errors with the following codes:
// - ErrStageLimitInvalidArg if the value type is not [int, long, double];
// - ErrStageLimitInvalidArg if the value is not a whole number or is NaN;
// - ErrStageLimitInvalidArg if the value is not in the range of int64;
Expand Down Expand Up @@ -162,7 +162,7 @@ func GetLimitStageParam(value any) (int64, error) {

// GetSkipStageParam returns $skip stage argument from the provided value.
//
// Returned errors:
// It returns command errors with the following codes:
// - ErrStageSkipBadValue if the value type is not [int, long, double];
// - ErrStageSkipBadValue if the value is not a whole number or is NaN;
// - ErrStageSkipBadValue if the value is not in the range of int64;
Expand Down Expand Up @@ -205,7 +205,7 @@ func GetSkipStageParam(value any) (int64, error) {
// getBinaryMaskParam matches value type, returning bit mask and error if match failed.
// Possible values are: position array ([1,3,5] == 010101), whole number value and types.Binary value.
//
// Returned errors:
// It returns command errors with the following codes:
// - ErrBadValue if positional argument is not a whole number of type [int, long, double];
// - ErrBadValue if positional argument is negative;
// - ErrFailedToParse if bitmask argument is not a whole number or negative;
Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/commonparams/extract_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import (
// If the field could have different types (e.g. `*types.Document` and `*types.Array`) then
// the field must be of type `any`.
//
// Errors list:
// It returns command errors with the following codes:
// - `ErrFailedToParse` when provided field is not present in passed structure;
// - `ErrFailedToParse` when provided field must be 0 or 1, but it is not;
// - `ErrNotImplemented` when support for provided field is not implemented yet;
Expand Down
6 changes: 3 additions & 3 deletions internal/handlers/commonparams/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func GetWholeNumberParam(value any) (int64, error) {
//
// # If the value is valid, it returns its int64 representation
//
// Command errors:
// It returns command errors with the following codes:
// - ErrTypeMismatch if the value is not of types [int, long, double, null];
chilagrow marked this conversation as resolved.
Show resolved Hide resolved
// - ErrValueNegative if the value is negative;
func getWholeParamStrict(command string, param string, value any) (int64, error) {
Expand Down Expand Up @@ -131,7 +131,7 @@ func getWholeParamStrict(command string, param string, value any) (int64, error)

// getOptionalPositiveNumber returns doc's value for key.
//
// Return errors:
// It returns command errors with the following codes:
// - ErrBadValue if value is not a number;
// - ErrBadValue if value is not of types [int, long];
// - ErrBadValue if value exceeds int32 range;
Expand Down Expand Up @@ -187,7 +187,7 @@ func getOptionalPositiveNumber(key string, value any) (int64, error) {
// GetBoolOptionalParam returns bool value of v.
// Non-zero double, long, and int values return true.
// Zero values for those types, as well as nulls and missing fields, return false.
// Other types return ErrTypeMismatch command error.
// Other types return command error with ErrTypeMismatch code.
func GetBoolOptionalParam(key string, v any) (bool, error) {
switch v := v.(type) {
case float64:
Expand Down