Skip to content

Conversation

@gocanto
Copy link
Collaborator

@gocanto gocanto commented May 30, 2025

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented May 30, 2025

📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • Updated package and import paths throughout the codebase for improved consistency and structure.
    • Updated type signatures and field types in several components to reflect new package naming.
    • Enhanced middleware logging to use structured logging for better clarity.
  • Chores
    • Added a new utility for creating a default validator with required struct validation enabled.
    • Minor comment corrections and non-functional updates.

Walkthrough

The changes systematically rename and reorganise package imports and references from webkit and bootstrap to pkg and boost respectively throughout the codebase. All affected types, function signatures, and struct field types are updated accordingly. No business logic or control flow is altered, except for improved logging in middleware and minor comment corrections.

Changes

Files / Groups Change Summary
api/users/create_handler.go, api/users/repository.go, api/users/users_schema.go Updated import paths from webkit to pkg and associated subpackages; updated type references.
bootstrap/validate.go, boost/validate.go Moved and renamed validator creation logic from bootstrap to boost; function signature and type updated to use pkg.Validator.
database/seeder/main.go Changed imports from bootstrap/cli to boost/pkg/cli; updated function calls to use new package.
database/seeder/seeds/*.go Updated gorm import path from webkit/gorm to pkg/gorm.
main.go Changed imports and type references from bootstrap/webkit to boost/pkg; updated global variable types and function calls.
pkg/handler.go, pkg/request/request.go Changed package declaration or import path from webkit to pkg.
pkg/media/support.go Minor correction in comment text.
pkg/middleware/middlewares.go, pkg/middleware/schema.go Updated imports from webkit to pkg; updated middleware type signatures; switched logging to use slog instead of println.
pkg/sentry.go, pkg/stringable.go, pkg/validator.go Changed package declaration from webkit to pkg.
boost/app.go, boost/boost.go, boost/spark.go Renamed package from bootstrap to boost; updated all related type and function references from webkit to pkg.
config/makefile/env.mk No effective change; line removed and re-added identically.

Sequence Diagram(s)

sequenceDiagram
    participant Main
    participant Boost
    participant Pkg
    participant Env

    Main->>Boost: Spark(envPath)
    Boost->>Pkg: MakeValidatorFrom(baseValidator)
    Boost->>Env: MakeEnv(values, validator)
    Main->>Boost: MakeDbConnection()
    Main->>Boost: MakeLogs()
    Main->>Boost: MakeAdminUser()
    Main->>Boost: MakeSentry(env)
    Main->>Boost: MakeApp(App{...})
    Boost->>Pkg: CreateHandle()
    Main->>Pkg: Use Validator, Sentry, etc.
Loading
sequenceDiagram
    participant Middleware
    participant Slog
    participant NextHandler

    Middleware->>Slog: Info("Request started", ...)
    Middleware->>NextHandler: ServeHTTP()
    Middleware->>Slog: Error("Request error", ...) (if error)
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gocanto gocanto changed the title Feature/files structure Files structure May 30, 2025
Copy link

@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.

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aa8070e and dd91ad0.

📒 Files selected for processing (27)
  • api/users/create_handler.go (2 hunks)
  • api/users/repository.go (1 hunks)
  • api/users/users_schema.go (1 hunks)
  • bootstrap/app.go (2 hunks)
  • bootstrap/boostrap.go (3 hunks)
  • bootstrap/spark.go (1 hunks)
  • bootstrap/validate.go (1 hunks)
  • database/seeder/main.go (1 hunks)
  • database/seeder/seeds/categories.go (1 hunks)
  • database/seeder/seeds/likes.go (1 hunks)
  • database/seeder/seeds/newsletters.go (1 hunks)
  • database/seeder/seeds/post_categories.go (1 hunks)
  • database/seeder/seeds/post_tags.go (1 hunks)
  • database/seeder/seeds/post_views.go (1 hunks)
  • database/seeder/seeds/posts.go (1 hunks)
  • database/seeder/seeds/tags.go (1 hunks)
  • database/seeder/seeds/users.go (1 hunks)
  • main.go (1 hunks)
  • pkg/handler.go (1 hunks)
  • pkg/media/support.go (1 hunks)
  • pkg/middleware/middlewares.go (1 hunks)
  • pkg/middleware/schema.go (2 hunks)
  • pkg/request/request.go (1 hunks)
  • pkg/sentry.go (1 hunks)
  • pkg/stringable.go (1 hunks)
  • pkg/validator.go (1 hunks)
  • webkit/middleware/middlewares.go (0 hunks)
💤 Files with no reviewable changes (1)
  • webkit/middleware/middlewares.go
🧰 Additional context used
🧬 Code Graph Analysis (7)
api/users/create_handler.go (1)
pkg/handler.go (1)
  • SendJSON (24-41)
api/users/users_schema.go (1)
pkg/validator.go (1)
  • Validator (11-14)
pkg/middleware/schema.go (1)
pkg/handler.go (1)
  • BaseHandler (10-10)
bootstrap/validate.go (1)
pkg/validator.go (2)
  • Validator (11-14)
  • MakeValidatorFrom (16-21)
main.go (1)
pkg/validator.go (1)
  • Validator (11-14)
bootstrap/spark.go (2)
env/env.go (1)
  • Environment (3-9)
pkg/validator.go (1)
  • Validator (11-14)
bootstrap/boostrap.go (3)
env/env.go (1)
  • Environment (3-9)
pkg/sentry.go (1)
  • Sentry (8-12)
pkg/validator.go (1)
  • Validator (11-14)
🔇 Additional comments (32)
pkg/stringable.go (1)

1-1: Package declaration updated to pkg.
The package name has been correctly changed from webkit to pkg in line with the broader refactoring.

database/seeder/seeds/newsletters.go (1)

6-6: Update gorm import path to pkg.
This import change to "github.com/gocanto/blog/pkg/gorm" ensures consistency with the renamed package. Ensure the project’s module definitions reflect this update.

database/seeder/seeds/categories.go (1)

6-6: Change gorm import to new package structure.
The import path now uses "github.com/gocanto/blog/pkg/gorm", keeping the seeder aligned with the refactored codebase.

database/seeder/seeds/post_categories.go (1)

6-6: Updated gorm import path to pkg/gorm
The import for gorm has been correctly changed to "github.com/gocanto/blog/pkg/gorm", aligning with the new package organisation across seeders.

database/seeder/seeds/post_views.go (1)

6-6: Updated gorm import path to pkg/gorm
The gorm import has been updated to the new "github.com/gocanto/blog/pkg/gorm" path, maintaining consistency with the refactored package layout.

database/seeder/seeds/posts.go (1)

6-6: Updated gorm import path to pkg/gorm
The gorm import now references "github.com/gocanto/blog/pkg/gorm", matching the restructuring of the codebase’s packages.

database/seeder/seeds/tags.go (1)

6-6: Updated gorm import path to pkg/gorm
The import path has been correctly switched to "github.com/gocanto/blog/pkg/gorm", consistent with other seeders.

database/seeder/seeds/post_tags.go (1)

6-6: Updated gorm import path to pkg/gorm
The gorm import has been updated to use "github.com/gocanto/blog/pkg/gorm", ensuring uniformity across the seeder files.

api/users/repository.go (1)

6-6: Updated GORM import path
The import path has been correctly updated to github.com/gocanto/blog/pkg/gorm, reflecting the new pkg namespace.

pkg/request/request.go (1)

6-6: Updated media import path
The import for the media package has been updated to github.com/gocanto/blog/pkg/media, matching the reorganised pkg structure.

database/seeder/main.go (1)

8-8: Updated CLI import path
The import path for the CLI helper has been correctly switched to github.com/gocanto/blog/pkg/cli in line with the package restructure.

pkg/validator.go (1)

1-1: Updated package declaration
The package declaration has been changed from webkit to pkg to align with the overall refactoring.

pkg/sentry.go (1)

1-1: Package declaration update looks good.

The package declaration change from webkit to pkg is consistent with the systematic package restructuring across the codebase.

pkg/handler.go (2)

1-1: Package declaration correctly updated.

The package name change to pkg aligns with the systematic refactoring.


5-5: Import path properly updated.

The import path change from webkit/response to pkg/response maintains consistency with the package restructuring whilst preserving functionality.

api/users/create_handler.go (2)

8-11: Import paths systematically updated.

The import path changes from webkit/* to pkg/* are consistent with the package restructuring and maintain all required functionality.


79-79: Function call correctly updated.

The change from webkit.SendJSON to pkg.SendJSON is appropriate and maintains the same functionality. The SendJSON function is confirmed to exist in pkg/handler.go (lines 24-41).

api/users/users_schema.go (2)

4-4: Import path appropriately updated.

The import change from webkit to pkg maintains consistency with the systematic package restructuring.


8-8: Type reference correctly updated.

The change from *webkit.Validator to *pkg.Validator is consistent with the package restructuring. The Validator struct is confirmed to exist in the pkg package.

pkg/middleware/schema.go (2)

5-5: LGTM! Import path updated correctly.

The import path has been successfully updated from the webkit package to the new pkg package structure.


14-14: Type alias updated correctly for new package structure.

The Middleware type alias now correctly references pkg.BaseHandler instead of webkit.BaseHandler, maintaining the same function signature whilst aligning with the package restructuring.

main.go (2)

6-6: Import path migration completed successfully.

The import has been correctly updated to use the new pkg package structure.


13-13: Validator type reference updated appropriately.

The global validator variable now correctly uses *pkg.Validator instead of *webkit.Validator, maintaining consistency with the package restructuring.

bootstrap/app.go (3)

7-9: Import paths successfully migrated to new package structure.

All import paths have been consistently updated from the webkit package hierarchy to the new pkg package structure, including core components and middleware.


14-14: Struct field types updated consistently.

The App struct fields now correctly reference types from the new pkg package (*pkg.Validator and *pkg.Sentry) instead of the old webkit package, maintaining type safety during the migration.

Also applies to: 20-20


39-39:

✅ Verification successful

Verify that pkg.CreateHandle function exists and maintains compatibility.

The function call has been updated to use pkg.CreateHandle instead of webkit.CreateHandle. Please ensure this function exists in the new package with the same signature.


🏁 Script executed:

#!/bin/bash
# Description: Verify that pkg.CreateHandle function exists with expected signature
# Expected: Function should exist and accept similar parameters as the old webkit.CreateHandle

# Search for CreateHandle function definition in pkg package
ast-grep --pattern 'func CreateHandle($$$) $$$'

Length of output: 648


🏁 Script executed:

#!/usr/bin/env bash
set -e

echo "Searching for all CreateHandle definitions in the repository:"
rg --no-heading --with-filename --line-number "func CreateHandle" .

echo
echo "Searching for BaseHandler type in pkg package:"
rg --no-heading --with-filename --line-number "type BaseHandler" pkg

echo
# Check if a local webkit package exists
if [ -d "webkit" ]; then
  echo "Found local webkit directory; searching there as well:"
  rg --no-heading --with-filename --line-number "func CreateHandle" webkit
  rg --no-heading --with-filename --line-number "type BaseHandler" webkit
else
  echo "No local webkit directory found."
fi

Length of output: 674


pkg.CreateHandle signature verified
The CreateHandle function is defined in pkg/handler.go (lines 10–22) with the signature

func CreateHandle(callback BaseHandler) http.HandlerFunc

and BaseHandler (pkg/handler.go:10) is

type BaseHandler func(w http.ResponseWriter, r *http.Request) *response.Response

This matches the expected signature of the old webkit.CreateHandle. No further changes are needed.

bootstrap/validate.go (2)

5-5: Import path correctly updated for validator package.

The import has been successfully migrated from webkit to the new pkg package structure.


8-9: Function signature and implementation updated consistently.

Both the return type and function call have been correctly updated to use the new pkg package. The MakeValidatorFrom function maintains the same signature and behaviour, ensuring seamless migration.

bootstrap/spark.go (1)

5-5:

✅ Verification successful

LGTM! Package refactoring looks consistent.

The import path and return type changes from webkit to pkg are correctly applied. The function logic remains unchanged, which is appropriate for a package refactoring.

Please verify that all references to webkit.Validator have been consistently updated across the codebase:

Also applies to: 9-9


🏁 Script executed:

#!/bin/bash
# Search for any remaining webkit.Validator references
rg "webkit\.Validator" --type go

Length of output: 34


All webkit.Validator references have been removed
No occurrences of webkit.Validator were found in the codebase, so the refactoring is complete and consistent.

bootstrap/boostrap.go (1)

9-10: LGTM! Comprehensive package refactoring correctly implemented.

All import paths and type references have been consistently updated from webkit to pkg:

  • Import statements properly updated to new package paths
  • Function return types correctly changed
  • Struct constructors properly updated
  • Parameter types accurately modified

The refactoring maintains all existing functionality whilst migrating to the new package structure.

Also applies to: 17-17, 32-32, 66-66

pkg/middleware/middlewares.go (2)

26-36: LGTM! AdminUser middleware logic is sound.

The authentication flow is properly implemented:

  • Extracts API key from header
  • Validates against admin user resolver
  • Returns appropriate unauthorized response when invalid

42-49: LGTM! Middleware composition logic is correct.

The Push method correctly applies middleware in reverse order, ensuring the first middleware in the list executes first in the request flow. This is the standard pattern for middleware composition.

Copy link

@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.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd91ad0 and c4f0535.

📒 Files selected for processing (1)
  • pkg/middleware/middlewares.go (1 hunks)
🔇 Additional comments (2)
pkg/middleware/middlewares.go (2)

1-10: LGTM! Imports are well-organised and appropriate.

The package declaration and imports look good. The migration from webkit to pkg package is consistent, and the inclusion of log/slog shows the structured logging approach has been adopted.


42-49: LGTM! Middleware composition is correctly implemented.

The Push method correctly applies middleware in reverse order, ensuring the first middleware in the list executes first. The comment clearly explains this behaviour, and the implementation is sound.

@gocanto gocanto marked this pull request as ready for review May 30, 2025 03:34
Copy link

@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.

Actionable comments posted: 1

♻️ Duplicate comments (3)
pkg/middleware/middlewares.go (3)

12-24: Logging improvements are good, but error context still needs enhancement.

The migration from println to slog is excellent and addresses previous feedback. However, the error logging could still benefit from additional request context for better debugging.

Consider enhancing the error logging with more context:

         if err != nil {
-            slog.Error(fmt.Sprintf("Handler returned error: %s", err))
+            slog.Error(fmt.Sprintf("Handler returned error: %s [method:%s] [path:%s]", err, r.Method, r.URL.Path))
         }

26-36: Variable naming issue persists: 'salt' should be renamed to 'apiKey'.

The function signature change is correct, but the misleading variable name from previous reviews hasn't been addressed.

Apply this diff to improve clarity:

 func (s MiddlewaresStack) AdminUser(next pkg.BaseHandler) pkg.BaseHandler {
     return func(w http.ResponseWriter, r *http.Request) *response.Response {
-        salt := r.Header.Get(env.ApiKeyHeader)
+        apiKey := r.Header.Get(env.ApiKeyHeader)
 
-        if s.isAdminUser(salt) {
+        if s.isAdminUser(apiKey) {
             return next(w, r)
         }
 
         return response.Unauthorized("Unauthorised", nil)
     }
 }

38-40: Unnecessary wrapper method should be reconsidered.

The isAdminUser method remains a simple wrapper around userAdminResolver without adding value, as noted in previous reviews.

Consider calling s.userAdminResolver directly in the AdminUser middleware, or add meaningful logic to this method if it serves a specific purpose.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b5e118 and e960449.

📒 Files selected for processing (2)
  • config/makefile/env.mk (1 hunks)
  • pkg/middleware/middlewares.go (2 hunks)
🔇 Additional comments (2)
pkg/middleware/middlewares.go (2)

4-10: LGTM! Import changes align with package refactoring.

The import changes correctly update the package references from webkit to pkg and add necessary imports for improved logging functionality.


42-49: LGTM! Function signature correctly updated.

The function signature change from webkit.BaseHandler to pkg.BaseHandler is consistent with the package refactoring.

@gocanto gocanto merged commit db2f1c0 into main May 30, 2025
2 checks passed
@gocanto gocanto deleted the feature/files-structure branch May 30, 2025 03:37
@coderabbitai coderabbitai bot mentioned this pull request Jun 18, 2025
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.

2 participants