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
)
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)
}

View File

@ -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)
}