-
Notifications
You must be signed in to change notification settings - Fork 2
/
generic_types.go
30 lines (20 loc) · 1.28 KB
/
generic_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package generics
type NotErrorGeneric[T float64 | int] struct {
Limit T
}
type SomeError[T ~string] struct{ Code T }
func (e SomeError[T]) Error() string { return string(e.Code) }
type SomePtrError[T ~string] struct{ Code T }
func (e *SomePtrError[T]) Error() string { return string(e.Code) }
type someErr[T ~string] struct{ Code T } // want "the type name `someErr` should conform to the `xxxError` format"
func (e someErr[T]) Error() string { return string(e.Code) }
type SomePtrErr[T ~string] struct{ Code T } // want "the type name `SomePtrErr` should conform to the `XxxError` format"
func (e *SomePtrErr[T]) Error() string { return string(e.Code) }
var (
ErrOK = &SomePtrError[string]{Code: "200 OK"}
okErr = &SomePtrError[string]{Code: "200 OK"} // want "the variable name `okErr` should conform to the `errXxx` format"
ErrNotFound = SomeError[string]{Code: "Not Found"}
NotFoundErr = SomeError[string]{Code: "Not Found"} // want "the variable name `NotFoundErr` should conform to the `ErrXxx` format"
statusCodeError = new(SomePtrError[string]) // want "the variable name `statusCodeError` should conform to the `errXxx` format"
ExplicitError error = new(SomePtrError[string]) // want "the variable name `ExplicitError` should conform to the `ErrXxx` format"
)