Add solution for Challenge 5 by hvijaycse#1484
Conversation
WalkthroughA new Go HTTP server module is introduced with token-based authentication. The module defines an AuthMiddleware function that validates requests against the X-Auth-Token header and exposes a SetupServer function that registers two routes: /hello (public) and /secure (protected). Invalid tokens return 401 Unauthorized responses. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
challenge-5/submissions/hvijaycse/solution-template.go (2)
30-30: Make the/securecomment method-agnostic.Line 30 currently reads as if
/secureshould be GET-only, but this handler intentionally accepts other methods too. Rewording the comment avoids nudging a future change that would break the"Different method on /secure with valid token"case.
14-15: Simplify the token check and use idiomatic local naming.
auth_header != validTokenalready rejects the missing-header case, so thelen(...) == 0branch is redundant. While touching this, renaming the local toauthHeaderwould match typical Go style.♻️ Minimal cleanup
- auth_header := r.Header.Get("X-Auth-Token") - if len(auth_header) == 0 || auth_header != validToken { + authHeader := r.Header.Get("X-Auth-Token") + if authHeader != validToken {
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ca3112cf-18cc-4cc8-9cac-788e5b31b926
📒 Files selected for processing (1)
challenge-5/submissions/hvijaycse/solution-template.go
Challenge 5 Solution
Submitted by: @hvijaycse
Challenge: Challenge 5
Description
This PR contains my solution for Challenge 5.
Changes
challenge-5/submissions/hvijaycse/solution-template.goTesting
Thank you for reviewing my submission! 🚀