-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper function that can prevent errors and reduce log noise (#142)
* Add helper function that can prevent errors and reduce log noise * Fix reference to a file in readme
- Loading branch information
Showing
3 changed files
with
48 additions
and
3 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,27 @@ | ||
package gateway | ||
|
||
import "github.com/grpc-ecosystem/grpc-gateway/utilities" | ||
|
||
// DefaultQueryFilter can be set to override the filter_{service}_{rpc}_{num} | ||
// field in generated .pb.gw.go files to prevent parse errors in the gateway | ||
// and potentially reduce log noise due to unrecognized fields | ||
var DefaultQueryFilter = utilities.NewDoubleArray(defaultFilterFields) | ||
|
||
var defaultFilterFields = [][]string{ | ||
// collection ops and the expected names used for the collection ops objects in requests | ||
{"paging"}, {limitQueryKey}, {offsetQueryKey}, {pageTokenQueryKey}, | ||
{"order_by"}, {sortQueryKey}, | ||
{"fields"}, {fieldsQueryKey}, | ||
{"filter"}, {filterQueryKey}, | ||
} | ||
|
||
// QueryFilterWith will add extra fields to the standard fields in the default | ||
// filter. | ||
func QueryFilterWith(extraFields []string) *utilities.DoubleArray { | ||
qf := make([][]string, len(defaultFilterFields)+len(extraFields)) | ||
copy(qf, defaultFilterFields) | ||
for _, f := range extraFields { | ||
qf = append(qf, []string{f}) | ||
} | ||
return utilities.NewDoubleArray(qf) | ||
} |
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