generated from bool64/go-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add middlewares and validation support (#4)
- Loading branch information
Showing
10 changed files
with
488 additions
and
23 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,47 @@ | ||
package jsonrpc | ||
|
||
import ( | ||
"sort" | ||
|
||
"github.com/swaggest/usecase/status" | ||
) | ||
|
||
// ErrWithFields exposes structured context of error. | ||
type ErrWithFields interface { | ||
error | ||
Fields() map[string]interface{} | ||
} | ||
|
||
// ErrWithAppCode exposes application error code. | ||
type ErrWithAppCode interface { | ||
error | ||
AppErrCode() int | ||
} | ||
|
||
// ErrWithCanonicalStatus exposes canonical status code. | ||
type ErrWithCanonicalStatus interface { | ||
error | ||
Status() status.Code | ||
} | ||
|
||
// ValidationErrors is a list of validation errors. | ||
// | ||
// Key is field position (e.g. "path:id" or "body"), value is a list of issues with the field. | ||
type ValidationErrors map[string][]string | ||
|
||
// Error returns error message. | ||
func (re ValidationErrors) Error() string { | ||
return "validation failed" | ||
} | ||
|
||
// Fields returns request errors by field location and name. | ||
func (re ValidationErrors) Fields() map[string]interface{} { | ||
res := make(map[string]interface{}, len(re)) | ||
|
||
for k, v := range re { | ||
sort.Strings(v) | ||
res[k] = v | ||
} | ||
|
||
return res | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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.