-
-
Notifications
You must be signed in to change notification settings - Fork 0
Files structure #28
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
Files structure #28
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe changes systematically rename and reorganise package imports and references from Changes
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.
sequenceDiagram
participant Middleware
participant Slog
participant NextHandler
Middleware->>Slog: Info("Request started", ...)
Middleware->>NextHandler: ServeHTTP()
Middleware->>Slog: Error("Request error", ...) (if error)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 5
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 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 topkg.
The package name has been correctly changed fromwebkittopkgin line with the broader refactoring.database/seeder/seeds/newsletters.go (1)
6-6: Updategormimport path topkg.
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: Changegormimport 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 forgormhas 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
Thegormimport 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
Thegormimport 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
Thegormimport 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 togithub.com/gocanto/blog/pkg/gorm, reflecting the newpkgnamespace.pkg/request/request.go (1)
6-6: Updated media import path
The import for themediapackage has been updated togithub.com/gocanto/blog/pkg/media, matching the reorganisedpkgstructure.database/seeder/main.go (1)
8-8: Updated CLI import path
The import path for the CLI helper has been correctly switched togithub.com/gocanto/blog/pkg/cliin line with the package restructure.pkg/validator.go (1)
1-1: Updated package declaration
The package declaration has been changed fromwebkittopkgto align with the overall refactoring.pkg/sentry.go (1)
1-1: Package declaration update looks good.The package declaration change from
webkittopkgis consistent with the systematic package restructuring across the codebase.pkg/handler.go (2)
1-1: Package declaration correctly updated.The package name change to
pkgaligns with the systematic refactoring.
5-5: Import path properly updated.The import path change from
webkit/responsetopkg/responsemaintains 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/*topkg/*are consistent with the package restructuring and maintain all required functionality.
79-79: Function call correctly updated.The change from
webkit.SendJSONtopkg.SendJSONis appropriate and maintains the same functionality. TheSendJSONfunction is confirmed to exist inpkg/handler.go(lines 24-41).api/users/users_schema.go (2)
4-4: Import path appropriately updated.The import change from
webkittopkgmaintains consistency with the systematic package restructuring.
8-8: Type reference correctly updated.The change from
*webkit.Validatorto*pkg.Validatoris consistent with the package restructuring. TheValidatorstruct is confirmed to exist in thepkgpackage.pkg/middleware/schema.go (2)
5-5: LGTM! Import path updated correctly.The import path has been successfully updated from the
webkitpackage to the newpkgpackage structure.
14-14: Type alias updated correctly for new package structure.The
Middlewaretype alias now correctly referencespkg.BaseHandlerinstead ofwebkit.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
pkgpackage structure.
13-13: Validator type reference updated appropriately.The global validator variable now correctly uses
*pkg.Validatorinstead 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
webkitpackage hierarchy to the newpkgpackage structure, including core components and middleware.
14-14: Struct field types updated consistently.The
Appstruct fields now correctly reference types from the newpkgpackage (*pkg.Validatorand*pkg.Sentry) instead of the oldwebkitpackage, 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.CreateHandleinstead ofwebkit.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." fiLength of output: 674
pkg.CreateHandle signature verified
TheCreateHandlefunction is defined inpkg/handler.go(lines 10–22) with the signaturefunc CreateHandle(callback BaseHandler) http.HandlerFuncand
BaseHandler(pkg/handler.go:10) istype BaseHandler func(w http.ResponseWriter, r *http.Request) *response.ResponseThis 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
webkitto the newpkgpackage structure.
8-9: Function signature and implementation updated consistently.Both the return type and function call have been correctly updated to use the new
pkgpackage. TheMakeValidatorFromfunction 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
webkittopkgare correctly applied. The function logic remains unchanged, which is appropriate for a package refactoring.Please verify that all references to
webkit.Validatorhave 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 goLength of output: 34
All
webkit.Validatorreferences have been removed
No occurrences ofwebkit.Validatorwere 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
webkittopkg:
- 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
Pushmethod 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.
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.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 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
webkittopkgpackage is consistent, and the inclusion oflog/slogshows the structured logging approach has been adopted.
42-49: LGTM! Middleware composition is correctly implemented.The
Pushmethod 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.
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.
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
printlntoslogis 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
isAdminUsermethod remains a simple wrapper arounduserAdminResolverwithout adding value, as noted in previous reviews.Consider calling
s.userAdminResolverdirectly in theAdminUsermiddleware, or add meaningful logic to this method if it serves a specific purpose.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 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
webkittopkgand add necessary imports for improved logging functionality.
42-49: LGTM! Function signature correctly updated.The function signature change from
webkit.BaseHandlertopkg.BaseHandleris consistent with the package refactoring.
No description provided.