From 3e1cbec54135d6402333e01316c758cf9df7fdb7 Mon Sep 17 00:00:00 2001 From: some Date: Tue, 1 Oct 2024 17:43:55 -0400 Subject: [PATCH] Move from pointer errors to interface --- server/callback.go | 23 +++++++++++------------ server/token.go | 23 +++++++++++------------ 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/server/callback.go b/server/callback.go index 2faf86e..a4df6d1 100644 --- a/server/callback.go +++ b/server/callback.go @@ -19,12 +19,12 @@ const ( CallbackErrorServerError ) -func (ce *CallbackError) Ok() bool { - return *ce == CallbackOk +func (ce CallbackError) Ok() bool { + return ce == CallbackOk } -func (ce *CallbackError) HttpStatus() (code int) { - switch *ce { +func (ce CallbackError) HttpStatus() (code int) { + switch ce { case CallbackOk: code = http.StatusOK case CallbackErrorUnimplemented: @@ -37,8 +37,8 @@ func (ce *CallbackError) HttpStatus() (code int) { return } -func (ce *CallbackError) String() (out string) { - switch *ce { +func (ce CallbackError) String() (out string) { + switch ce { case CallbackOk: out = "authenticated" case CallbackErrorUnimplemented: @@ -51,9 +51,9 @@ func (ce *CallbackError) String() (out string) { return } -func (ce *CallbackError) ErrorResponse() []byte { +func (ce CallbackError) ErrorResponse() []byte { var msg string - switch *ce { + switch ce { default: msg = "internal_server_error" } @@ -100,13 +100,12 @@ type UnimplementedCallbackServer struct{} func (u UnimplementedCallbackServer) mustEmbedUnimplementedCallbackServer() {} -func (u UnimplementedCallbackServer) Callback(req *CallbackRequest) (res *CallbackResponse, errRes *CallbackError) { - ce := CallbackErrorUnimplemented - errRes = &ce +func (u UnimplementedCallbackServer) Callback(req *CallbackRequest) (res *CallbackResponse, errRes ErrorResponse) { + errRes = CallbackErrorUnimplemented return } type CallbackServer interface { mustEmbedUnimplementedCallbackServer() - Callback(*CallbackRequest) (*CallbackResponse, *CallbackError) + Callback(*CallbackRequest) (*CallbackResponse, ErrorResponse) } diff --git a/server/token.go b/server/token.go index 1c87cf1..324dfc6 100644 --- a/server/token.go +++ b/server/token.go @@ -21,12 +21,12 @@ const ( TokenErrorPending ) -func (te *TokenError) Ok() bool { - return *te == TokenOk +func (te TokenError) Ok() bool { + return te == TokenOk } -func (te *TokenError) HttpStatus() (code int) { - switch *te { +func (te TokenError) HttpStatus() (code int) { + switch te { case TokenOk: code = http.StatusOK case TokenErrorUnimplemented: @@ -43,8 +43,8 @@ func (te *TokenError) HttpStatus() (code int) { return } -func (te *TokenError) String() (out string) { - switch *te { +func (te TokenError) String() (out string) { + switch te { case TokenOk: out = "authenticated" case TokenErrorUnimplemented: @@ -61,9 +61,9 @@ func (te *TokenError) String() (out string) { return } -func (te *TokenError) ErrorResponse() []byte { +func (te TokenError) ErrorResponse() []byte { var msg string - switch *te { + switch te { case TokenErrorSlowDown: msg = "slow_down" case TokenErrorPending: @@ -117,13 +117,12 @@ type UnimplementedTokenServer struct{} func (u UnimplementedTokenServer) mustEmbedUnimplementedTokenServer() {} -func (u UnimplementedTokenServer) Token(req *TokenRequest) (res *TokenResponse, errRes *TokenError) { - te := TokenErrorUnimplemented - errRes = &te +func (u UnimplementedTokenServer) Token(req *TokenRequest) (res *TokenResponse, errRes ErrorResponse) { + errRes = TokenErrorUnimplemented return } type TokenServer interface { mustEmbedUnimplementedTokenServer() - Token(*TokenRequest) (*TokenResponse, *TokenError) + Token(*TokenRequest) (*TokenResponse, ErrorResponse) }