Skip to content

Add solution for Challenge 5 by hvijaycse#1484

Open
hvijaycse wants to merge 1 commit intoRezaSi:mainfrom
hvijaycse:challenge-5-hvijaycse
Open

Add solution for Challenge 5 by hvijaycse#1484
hvijaycse wants to merge 1 commit intoRezaSi:mainfrom
hvijaycse:challenge-5-hvijaycse

Conversation

@hvijaycse
Copy link

Challenge 5 Solution

Submitted by: @hvijaycse
Challenge: Challenge 5

Description

This PR contains my solution for Challenge 5.

Changes

  • Added solution file to challenge-5/submissions/hvijaycse/solution-template.go

Testing

  • Solution passes all test cases
  • Code follows Go best practices

Thank you for reviewing my submission! 🚀

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

Walkthrough

A 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

Cohort / File(s) Summary
HTTP Server with Authentication
challenge-5/submissions/hvijaycse/solution-template.go
Adds AuthMiddleware for X-Auth-Token validation, SetupServer function to configure routes and handlers, helloHandler for public access, and secureHandler for authenticated requests.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A token-bearing door, now guarded well,
Public paths and secrets—each with its spell,
Middleware whispers: "Show your token true,"
Or 401 awaits those passing through! 🔐

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a solution for Challenge 5 by a specific contributor.
Description check ✅ Passed The description is directly related to the changeset, providing context about the Challenge 5 submission and the files being added.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ 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).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
challenge-5/submissions/hvijaycse/solution-template.go (2)

30-30: Make the /secure comment method-agnostic.

Line 30 currently reads as if /secure should 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 != validToken already rejects the missing-header case, so the len(...) == 0 branch is redundant. While touching this, renaming the local to authHeader would 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

📥 Commits

Reviewing files that changed from the base of the PR and between a7ac764 and 5462a11.

📒 Files selected for processing (1)
  • challenge-5/submissions/hvijaycse/solution-template.go

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