Skip to content

Simplify server JSON handler code for RPC methods #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 25, 2023

Conversation

VojtechVitek
Copy link
Contributor

No description provided.

@VojtechVitek VojtechVitek force-pushed the simplify_method_handler branch from 6c6c3f9 to 3134536 Compare August 25, 2023 11:40
@VojtechVitek VojtechVitek force-pushed the simplify_method_handler branch from 3134536 to f3a2c65 Compare August 25, 2023 11:42
No need to define defer-panic in JSON handler for each generated
RPC method, since the generated Go methods are private and called
only from within .ServerHTTP().
RespondWithError(w, ErrorWithCause(ErrWebrpcServerPanic, fmt.Errorf("%v", rr)))
panic(rr)
}
}()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the defer-panic up to the ServeHTTP() method.

No need to define defer-panic in JSON handler for each generated RPC method, since the generated Go methods are private and called only from within .ServerHTTP().

panic(rr)
}
}()
ret0, err = s.ExampleService.Status(ctx)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the service call to the main handler function. Remove the unnecessarry anonymous function and a defer call (which was moved up to the parent .ServeHTTP() method)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant