-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
11 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
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,46 @@ | ||
package generics | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"reflect" | ||
) | ||
|
||
type ( | ||
Req any | ||
Resp any | ||
) | ||
|
||
type timeoutErr[REQ Req, RESP Resp] struct { // want "the type name `timeoutErr` should conform to the `xxxError` format" | ||
err error | ||
sending bool | ||
} | ||
|
||
func (e *timeoutErr[REQ, RESP]) Error() string { | ||
var req REQ | ||
var resp RESP | ||
|
||
direction := "sending" | ||
if !e.sending { | ||
direction = "receiving" | ||
} | ||
|
||
return fmt.Sprintf("deferred call %T->%T timeout %s: %s", | ||
reflect.TypeOf(req), reflect.TypeOf(resp), direction, e.err.Error()) | ||
} | ||
|
||
func (e *timeoutErr[REQ, RESP]) Unwrap() error { | ||
return e.err | ||
} | ||
|
||
type TimeoutError[REQ Req, RESP Resp] struct{} // | ||
func (TimeoutError[REQ, RESP]) Error() string { return "timeouted" } | ||
|
||
type ValErr[A, B, C, D, E, F any] struct{} // want "the type name `ValErr` should conform to the `XxxError` format" | ||
func (ValErr[A, B, C, D, E, F]) Error() string { return "boom!" } | ||
|
||
var ( | ||
ErrTimeout error = &timeoutErr[*http.Request, *http.Response]{err: context.DeadlineExceeded, sending: false} | ||
tErr error = &timeoutErr[string, string]{err: context.DeadlineExceeded, sending: true} // want "the variable name `tErr` should conform to the `errXxx` format" | ||
) |