Move from pointer errors to interface

This commit is contained in:
some 2024-10-01 17:43:55 -04:00
parent 2f0e19ced9
commit 3e1cbec541
Signed by: some
GPG Key ID: 65D0589220B9BFC8
2 changed files with 22 additions and 24 deletions

View File

@ -19,12 +19,12 @@ const (
CallbackErrorServerError CallbackErrorServerError
) )
func (ce *CallbackError) Ok() bool { func (ce CallbackError) Ok() bool {
return *ce == CallbackOk return ce == CallbackOk
} }
func (ce *CallbackError) HttpStatus() (code int) { func (ce CallbackError) HttpStatus() (code int) {
switch *ce { switch ce {
case CallbackOk: case CallbackOk:
code = http.StatusOK code = http.StatusOK
case CallbackErrorUnimplemented: case CallbackErrorUnimplemented:
@ -37,8 +37,8 @@ func (ce *CallbackError) HttpStatus() (code int) {
return return
} }
func (ce *CallbackError) String() (out string) { func (ce CallbackError) String() (out string) {
switch *ce { switch ce {
case CallbackOk: case CallbackOk:
out = "authenticated" out = "authenticated"
case CallbackErrorUnimplemented: case CallbackErrorUnimplemented:
@ -51,9 +51,9 @@ func (ce *CallbackError) String() (out string) {
return return
} }
func (ce *CallbackError) ErrorResponse() []byte { func (ce CallbackError) ErrorResponse() []byte {
var msg string var msg string
switch *ce { switch ce {
default: default:
msg = "internal_server_error" msg = "internal_server_error"
} }
@ -100,13 +100,12 @@ type UnimplementedCallbackServer struct{}
func (u UnimplementedCallbackServer) mustEmbedUnimplementedCallbackServer() {} func (u UnimplementedCallbackServer) mustEmbedUnimplementedCallbackServer() {}
func (u UnimplementedCallbackServer) Callback(req *CallbackRequest) (res *CallbackResponse, errRes *CallbackError) { func (u UnimplementedCallbackServer) Callback(req *CallbackRequest) (res *CallbackResponse, errRes ErrorResponse) {
ce := CallbackErrorUnimplemented errRes = CallbackErrorUnimplemented
errRes = &ce
return return
} }
type CallbackServer interface { type CallbackServer interface {
mustEmbedUnimplementedCallbackServer() mustEmbedUnimplementedCallbackServer()
Callback(*CallbackRequest) (*CallbackResponse, *CallbackError) Callback(*CallbackRequest) (*CallbackResponse, ErrorResponse)
} }

View File

@ -21,12 +21,12 @@ const (
TokenErrorPending TokenErrorPending
) )
func (te *TokenError) Ok() bool { func (te TokenError) Ok() bool {
return *te == TokenOk return te == TokenOk
} }
func (te *TokenError) HttpStatus() (code int) { func (te TokenError) HttpStatus() (code int) {
switch *te { switch te {
case TokenOk: case TokenOk:
code = http.StatusOK code = http.StatusOK
case TokenErrorUnimplemented: case TokenErrorUnimplemented:
@ -43,8 +43,8 @@ func (te *TokenError) HttpStatus() (code int) {
return return
} }
func (te *TokenError) String() (out string) { func (te TokenError) String() (out string) {
switch *te { switch te {
case TokenOk: case TokenOk:
out = "authenticated" out = "authenticated"
case TokenErrorUnimplemented: case TokenErrorUnimplemented:
@ -61,9 +61,9 @@ func (te *TokenError) String() (out string) {
return return
} }
func (te *TokenError) ErrorResponse() []byte { func (te TokenError) ErrorResponse() []byte {
var msg string var msg string
switch *te { switch te {
case TokenErrorSlowDown: case TokenErrorSlowDown:
msg = "slow_down" msg = "slow_down"
case TokenErrorPending: case TokenErrorPending:
@ -117,13 +117,12 @@ type UnimplementedTokenServer struct{}
func (u UnimplementedTokenServer) mustEmbedUnimplementedTokenServer() {} func (u UnimplementedTokenServer) mustEmbedUnimplementedTokenServer() {}
func (u UnimplementedTokenServer) Token(req *TokenRequest) (res *TokenResponse, errRes *TokenError) { func (u UnimplementedTokenServer) Token(req *TokenRequest) (res *TokenResponse, errRes ErrorResponse) {
te := TokenErrorUnimplemented errRes = TokenErrorUnimplemented
errRes = &te
return return
} }
type TokenServer interface { type TokenServer interface {
mustEmbedUnimplementedTokenServer() mustEmbedUnimplementedTokenServer()
Token(*TokenRequest) (*TokenResponse, *TokenError) Token(*TokenRequest) (*TokenResponse, ErrorResponse)
} }