-
Notifications
You must be signed in to change notification settings - Fork 1.7k
refactor: auth service #2436
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
refactor: auth service #2436
Conversation
@0xEbrahim Thanks for making your contribution to GoFr. After running the workflow we got to know your PR has some linter errors, can you please resolve them so that we can reveiw the PR.
|
|
Yeah i will fix it >
|
|
@0xEbrahim I reviewed the refactoring and foudnd that this refactoring adds unnecessary complexity through the Go favors clarity over cleverness - the anonymous functions in methods like GetWithHeaders and DeleteWithHeaders create additional cognitive load without solving a significant problem. |
|
@0xEbrahim I was majorly referring to file
I feel that |
Such a great feedback, i will start working on |
|
|
||
| return a.HTTP.DeleteWithHeaders(ctx, path, body, headers) | ||
| return a.doAuthWithHeaders(ctx, | ||
| func(ctx context.Context, path string, _ map[string]any, body []byte, headers map[string]string) (*http.Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I am not a code owner. But I think it is better to leave initial
headers, err := a.auth(ctx, headers)
if err != nil {
return nil, err
}
return a.HTTP.DeleteWithHeaders(ctx, path, body, headers)for better readability. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, You are totally right, I over-refactored it
|
@0xEbrahim As discussed earlier, closing this PR as of now as |

Pull Request Template
Adresses: #2434
Description:
This PR refactors the pkg/gofr/service/auth.go file to eliminate duplicated logic across HTTP method implementations (Get, Post, Patch, Put, and Delete).
A new helper function doAuthWithHeaders was introduced to centralize the authentication and header injection process, significantly improving code maintainability and readability.
Key improvements:
Consolidated repetitive code that handled authentication and HTTP header merging into a single utility method doAuthWithHeaders.
Reduced boilerplate across all HTTP methods by reusing the same authentication logic.
Ensured consistent behavior for all request types (GET, POST, PATCH, PUT, DELETE).
Improved testability by isolating authentication header injection logic.
Enhanced readability and maintainability for future extension (e.g., adding HEAD, OPTIONS, or custom verbs).
Breaking Changes (if applicable):
None — this is a purely internal refactor; all public method signatures remain unchanged.
Checklist:
goimportandgolangci-lint.