-
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.
feat(Errors): Errors use interface can inject string or struct.
- Loading branch information
1 parent
5b20421
commit b9d6538
Showing
3 changed files
with
80 additions
and
30 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
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,35 @@ | ||
package ctx | ||
|
||
type ErrorProto struct { | ||
Items []ErrorProtoItem | ||
} | ||
|
||
type ErrorProtoItem struct { | ||
Domain string `json:"domain,omitempty"` | ||
Reason string `json:"reason,omitempty"` | ||
Message string `json:"message,omitempty"` | ||
Location string `json:"location,omitempty"` | ||
LocationType string `json:"location_type,omitempty"` | ||
ExtendedHelp string `json:"extended_help,omitempty"` | ||
SendReport string `json:"send_report,omitempty"` | ||
} | ||
|
||
func NewErrorProto() *ErrorProto { return &ErrorProto{} } | ||
|
||
func NewErrorProtoItem() *ErrorProtoItem { return &ErrorProtoItem{} } | ||
|
||
func (e *ErrorProto) Add(d ErrorProtoItem) *ErrorProto { | ||
|
||
e.Items = append(e.Items, d) | ||
|
||
return e | ||
} | ||
|
||
func (e *ErrorProto) AsErrors() []interface{} { | ||
|
||
errs := make([]interface{}, len(e.Items)) | ||
for i, v := range e.Items { | ||
errs[i] = v | ||
} | ||
return errs | ||
} |