Skip to content

refactor: replace utils package with core functions in template engines#446

Merged
ReneWerner87 merged 5 commits intomasterfrom
replace-utils-package-with-core
Jan 2, 2026
Merged

refactor: replace utils package with core functions in template engines#446
ReneWerner87 merged 5 commits intomasterfrom
replace-utils-package-with-core

Conversation

@ReneWerner87
Copy link
Copy Markdown
Member

@ReneWerner87 ReneWerner87 commented Jan 2, 2026

Summary by CodeRabbit

  • New Features

    • Added public utilities to read template files and traverse template directories.
  • Chores

    • Template engines now use the centralized file-operation utilities for consistency.
    • Added a Makefile with common development and quality targets.
    • Updated .gitignore to exclude Claude-related files.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings January 2, 2026 11:52
@ReneWerner87 ReneWerner87 requested a review from a team as a code owner January 2, 2026 11:52
@ReneWerner87 ReneWerner87 requested review from efectn, gaby and sixcolors and removed request for a team January 2, 2026 11:52
@ReneWerner87 ReneWerner87 added 🤖 Dependencies Pull requests that update a dependency file 🧹 Updates labels Jan 2, 2026
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @ReneWerner87, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the internal structure of the template engine implementations by consolidating common file reading and directory traversal utilities within the main core template package. This change aims to streamline the dependency management for individual template engines, ensuring they leverage a unified set of core functions for file system interactions rather than maintaining direct external dependencies for these common tasks.

Highlights

  • Centralized Utility Functions: The ReadFile and Walk utility functions have been moved from direct usage of github.com/gofiber/utils to being exposed directly by the core template package. This centralizes common file system operations.
  • Reduced Direct Dependencies: Individual template engines (Ace, Amber, Django, Handlebars, HTML, Jet, Mustache, Pug, Slim) no longer directly import github.com/gofiber/utils, simplifying their dependency trees.
  • Dependency Updates: The go.mod and go.sum files across all affected template engines have been updated to reflect the removal of the old gofiber/utils dependency and the indirect inclusion of gofiber/utils/v2 via the core template package.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a well-executed refactoring to decouple the various template engines from the gofiber/utils package. By centralizing the file system operations (ReadFile and Walk) into the core template package and providing them as wrapper functions, the individual engines now have a cleaner dependency tree. The changes are consistently applied across all template engine implementations, and the go.mod and go.sum files are updated accordingly. This is a solid improvement for the project's modularity and maintainability.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 2, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds .claude to .gitignore, introduces two exported wrapper functions ReadFile and Walk in template.go, and updates template engines to call the new local core wrappers instead of github.com/gofiber/utils.

Changes

Cohort / File(s) Summary
Configuration
\.gitignore
Added .claude entry to ignore Claude-related files.
Core Interface Layer
template.go
Added exported wrappers: ReadFile(path string, fs http.FileSystem) ([]byte, error) and Walk(fs http.FileSystem, directory string, walkFn func(path string, info os.FileInfo, err error) error) error (delegating internally to utils).
Template Engine Implementations
Engines: ace/ace.go, amber/amber.go, django/django.go, handlebars/handlebars.go, html/html.go, jet/jet.go, mustache/mustache.go, pug/pug.go, slim/slim.go
Replaced direct imports/calls to github.com/gofiber/utils with calls to the local core wrappers: utils.ReadFilecore.ReadFile, utils.Walkcore.Walk. Removed now-unused utils imports. No exported API changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped through code with nimble paws,

Swapped old utils for core’s new laws.
Templates stroll paths I gently paved,
.claude hidden, tidy and saved. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the pull request—replacing the utils package with core functions across multiple template engines.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch replace-utils-package-with-core

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
Copy Markdown

@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

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dffca19 and 7debd9d.

⛔ Files ignored due to path filters (19)
  • ace/go.mod is excluded by !**/*.mod
  • ace/go.sum is excluded by !**/*.sum, !**/*.sum
  • amber/go.mod is excluded by !**/*.mod
  • amber/go.sum is excluded by !**/*.sum, !**/*.sum
  • django/go.mod is excluded by !**/*.mod
  • django/go.sum is excluded by !**/*.sum, !**/*.sum
  • go.mod is excluded by !**/*.mod
  • handlebars/go.mod is excluded by !**/*.mod
  • handlebars/go.sum is excluded by !**/*.sum, !**/*.sum
  • html/go.mod is excluded by !**/*.mod
  • html/go.sum is excluded by !**/*.sum, !**/*.sum
  • jet/go.mod is excluded by !**/*.mod
  • jet/go.sum is excluded by !**/*.sum, !**/*.sum
  • mustache/go.mod is excluded by !**/*.mod
  • mustache/go.sum is excluded by !**/*.sum, !**/*.sum
  • pug/go.mod is excluded by !**/*.mod
  • pug/go.sum is excluded by !**/*.sum, !**/*.sum
  • slim/go.mod is excluded by !**/*.mod
  • slim/go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (11)
  • .gitignore
  • ace/ace.go
  • amber/amber.go
  • django/django.go
  • handlebars/handlebars.go
  • html/html.go
  • jet/jet.go
  • mustache/mustache.go
  • pug/pug.go
  • slim/slim.go
  • template.go
🧰 Additional context used
🧬 Code graph analysis (6)
jet/jet.go (1)
template.go (1)
  • ReadFile (176-178)
ace/ace.go (1)
template.go (2)
  • ReadFile (176-178)
  • Walk (184-186)
html/html.go (1)
template.go (2)
  • ReadFile (176-178)
  • Walk (184-186)
mustache/mustache.go (1)
template.go (2)
  • ReadFile (176-178)
  • Walk (184-186)
pug/pug.go (1)
template.go (2)
  • ReadFile (176-178)
  • Walk (184-186)
slim/slim.go (1)
template.go (2)
  • ReadFile (176-178)
  • Walk (184-186)
🪛 GitHub Actions: Golangci-Lint
template.go

[error] 11-11: could not import github.com/gofiber/utils/v2 (template.go:11:2: missing go.sum entry for module providing package github.com/gofiber/utils/v2 (imported by github.com/gofiber/template/v2); to add:)

🪛 GitHub Actions: Govulncheck Security Scan
template.go

[error] 11-11: govulncheck failed: missing go.sum entry for module providing package github.com/gofiber/utils/v2 (imported by github.com/gofiber/template/v2); to add:

🪛 GitHub Check: golangci-lint
template.go

[failure] 185-185:
undefined: utils (typecheck)


[failure] 177-177:
undefined: utils (typecheck)

🪛 GitHub Check: govulncheck-check
template.go

[failure] 11-11:
could not import github.com/gofiber/utils/v2 (invalid package name: "")


[failure] 11-11:
missing go.sum entry for module providing package github.com/gofiber/utils/v2 (imported by github.com/gofiber/template/v2); to add:


[failure] 185-185:
undefined: utils


[failure] 177-177:
undefined: utils

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Agent
  • GitHub Check: Compare
  • GitHub Check: Tests (1.25.x, windows-latest)
🔇 Additional comments (18)
.gitignore (1)

19-19: LGTM!

Adding .claude to the ignore list is appropriate for excluding tool-specific files from version control.

template.go (1)

173-186: Good architectural design with clear documentation.

The wrapper functions provide a clean abstraction layer, allowing template engines to use file operations without directly depending on the utils package. The documentation clearly explains the purpose of these wrappers.

Once the dependency issue is resolved, these implementations will work correctly.

html/html.go (1)

100-100: LGTM! Clean migration to core package functions.

The replacement of utils.ReadFile and utils.Walk with their core package equivalents is correct and maintains the existing logic. The error handling and control flow remain unchanged.

Also applies to: 123-123

pug/pug.go (1)

97-97: LGTM! Consistent refactoring pattern.

The migration from utils to core package functions follows the same clean pattern as other template engines. The file operations maintain their existing behavior and error handling.

Also applies to: 128-128

handlebars/handlebars.go (1)

93-93: LGTM! Refactoring completes the migration pattern.

The Handlebars engine successfully adopts the core package functions, completing the consistent refactoring across all template engines in this PR.

Also applies to: 113-113

amber/amber.go (2)

107-107: LGTM! Refactored to use core.ReadFile.

The replacement of utils.ReadFile with core.ReadFile is correct and maintains the same functionality through the wrapper function in template.go.


133-133: LGTM! Refactored to use core.Walk.

The replacement of utils.Walk with core.Walk is correct and maintains the same functionality through the wrapper function in template.go.

django/django.go (2)

122-122: LGTM! Refactored to use core.ReadFile.

The replacement is consistent with the refactoring pattern applied across all template engines.


144-144: LGTM! Refactored to use core.Walk.

The replacement is consistent with the refactoring pattern applied across all template engines.

ace/ace.go (2)

101-101: LGTM! Refactored to use core.ReadFile.

The replacement is correct and aligns with the unified file I/O interface provided by the core package.


137-137: LGTM! Refactored to use core.Walk.

The replacement is correct and aligns with the unified file I/O interface provided by the core package.

jet/jet.go (1)

126-126: LGTM! Refactored to use core.ReadFile.

The replacement is correct. Note that this engine appropriately continues using filepath.Walk directly at line 143 since it uses an InMemLoader rather than the FileSystem-based walking pattern.

mustache/mustache.go (3)

32-32: LGTM! Refactored to use core.ReadFile.

The replacement in the partial provider is correct and maintains the same functionality for loading partial templates.


111-111: LGTM! Refactored to use core.ReadFile.

The replacement is consistent with the refactoring pattern applied across all template engines.


139-139: LGTM! Refactored to use core.Walk.

The replacement is consistent with the refactoring pattern applied across all template engines.

slim/slim.go (3)

13-13: LGTM! Import aligns with refactoring objective.

The core package alias correctly references the template package that provides the centralized file operation wrappers.


88-88: LGTM! ReadFile call is correctly updated.

The refactoring properly uses the core package wrapper, maintaining identical behavior while centralizing the file operation interface.


120-120: LGTM! Walk call is correctly updated.

The refactoring properly uses the core package wrapper with the correct parameter order and types. Verified consistency across all template engines (ace, amber, django, handlebars, html, jet, mustache, pug): all are correctly using core.Walk and core.ReadFile with proper imports.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors template engine implementations to use wrapper functions in the core template package instead of directly importing the utils package. The refactor centralizes utils function calls (ReadFile and Walk) in template.go, with all template engines (slim, pug, mustache, jet, html, handlebars, django, amber, ace) updated to call these wrapper functions via the core package.

Key Changes

  • Added ReadFile and Walk wrapper functions to template.go that forward calls to utils/v2 package
  • Updated all template engines to replace utils.ReadFile with core.ReadFile and utils.Walk with core.Walk
  • Migrated from utils v1.2.0 to utils/v2 v2.0.0-rc.5, moving it from direct to indirect dependency in engine modules

Reviewed changes

Copilot reviewed 20 out of 30 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
template.go Added ReadFile and Walk wrapper functions that delegate to utils/v2 package
slim/slim.go Replaced utils.ReadFile and utils.Walk calls with core.ReadFile and core.Walk
pug/pug.go Replaced utils.ReadFile and utils.Walk calls with core.ReadFile and core.Walk
mustache/mustache.go Replaced utils.ReadFile and utils.Walk calls with core.ReadFile and core.Walk
jet/jet.go Replaced utils.ReadFile call with core.ReadFile
html/html.go Replaced utils.ReadFile and utils.Walk calls with core.ReadFile and core.Walk
handlebars/handlebars.go Replaced utils.ReadFile and utils.Walk calls with core.ReadFile and core.Walk
django/django.go Replaced utils.ReadFile and utils.Walk calls with core.ReadFile and core.Walk
amber/amber.go Replaced utils.ReadFile and utils.Walk calls with core.ReadFile and core.Walk
ace/ace.go Replaced utils.ReadFile and utils.Walk calls with core.ReadFile and core.Walk
go.mod Added utils/v2 v2.0.0-rc.5 as direct dependency; specifies Go version 1.25
*/go.mod Updated engine modules to have utils/v2 as indirect dependency instead of direct
*/go.sum Updated checksums for utils/v2 and its transitive dependencies
.gitignore Added .claude to ignored files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
template.go (1)

173-183: Simplify the error handling.

The explicit error check is redundant since you're just forwarding the result from utils.ReadFile. Directly returning the call result simplifies the code.

🔎 Proposed simplification
 func ReadFile(path string, fs http.FileSystem) ([]byte, error) {
-	buf, err := utils.ReadFile(path, fs)
-	if err != nil {
-		return nil, err
-	}
-	return buf, nil
+	return utils.ReadFile(path, fs)
 }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7debd9d and 8947569.

⛔ Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (1)
  • template.go
🧰 Additional context used
🪛 GitHub Actions: Golangci-Lint
template.go

[error] 191-191: golangci-lint (revive): if-return: redundant if ...; err != nil check, just return error instead.

🪛 GitHub Check: golangci-lint
template.go

[failure] 192-192:
error returned from external package is unwrapped: sig: func github.com/gofiber/utils/v2.Walk(fs net/http.FileSystem, root string, walkFn path/filepath.WalkFunc) error (wrapcheck)


[failure] 180-180:
error returned from external package is unwrapped: sig: func github.com/gofiber/utils/v2.ReadFile(path string, fs net/http.FileSystem) ([]byte, error) (wrapcheck)


[failure] 191-191:
if-return: redundant if ...; err != nil check, just return error instead. (revive)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Compare
  • GitHub Check: Tests (1.25.x, windows-latest)
🔇 Additional comments (1)
template.go (1)

7-7: LGTM: Necessary imports for the new wrapper functions.

The os import is required for the os.FileInfo type in the Walk function signature, and the utils/v2 import is needed for delegating to the underlying implementation.

Also applies to: 11-11

Copy link
Copy Markdown

@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

🧹 Nitpick comments (2)
Makefile (1)

19-24: Consider cross-platform compatibility for opening the coverage report.

The open command on Line 24 is macOS-specific. On Linux, use xdg-open; on Windows, use start. Consider either documenting this limitation or using a cross-platform solution.

🔎 Example cross-platform approach

Option 1: Remove the open command and document that users should open coverage.html manually:

 coverage:
 	go run gotest.tools/gotestsum@v1.12.0 -f testname -- ./... -race -count=1 -coverprofile=coverage.out -covermode=atomic
 	go tool cover -html=coverage.out -o coverage.html
-	open coverage.html &
+	@echo "Coverage report generated: coverage.html"

Option 2: Add OS detection:

 coverage:
 	go run gotest.tools/gotestsum@v1.12.0 -f testname -- ./... -race -count=1 -coverprofile=coverage.out -covermode=atomic
 	go tool cover -html=coverage.out -o coverage.html
-	open coverage.html &
+	@case "$$(uname -s)" in \
+		Darwin) open coverage.html & ;; \
+		Linux) xdg-open coverage.html & ;; \
+		MINGW*|MSYS*) start coverage.html & ;; \
+	esac
template.go (1)

186-196: Consider refactoring to address linter feedback on error handling pattern.

The linter flagged the if err := ...; err != nil pattern in past reviews. While the logic is correct, you can satisfy the linter by splitting the assignment from the condition check:

🔎 Alternative pattern to address linter feedback
 func Walk(fs http.FileSystem, directory string, walkFn func(path string, info os.FileInfo, err error) error) error {
-	if err := utils.Walk(fs, directory, walkFn); err != nil {
+	err := utils.Walk(fs, directory, walkFn)
+	if err != nil {
 		return fmt.Errorf("failed to walk directory: %w", err)
 	}
 	return nil
 }

This maintains the error wrapping while using a pattern that linters typically prefer.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8947569 and 2011aeb.

📒 Files selected for processing (2)
  • Makefile
  • template.go
🧰 Additional context used
🪛 checkmake (0.2.2)
Makefile

[warning] 52-52: Missing required phony target "all"

(minphony)


[warning] 52-52: Missing required phony target "clean"

(minphony)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Tests (1.25.x, windows-latest)
  • GitHub Check: Compare
🔇 Additional comments (2)
template.go (2)

4-13: LGTM!

The import additions (fmt, os) are appropriate for the new wrapper functions that format errors and handle file info types.


174-184: LGTM!

The ReadFile wrapper correctly delegates to utils.ReadFile and properly wraps errors with context while preserving the error chain using %w.

@ReneWerner87 ReneWerner87 merged commit 95531cb into master Jan 2, 2026
37 checks passed
@ReneWerner87 ReneWerner87 deleted the replace-utils-package-with-core branch January 2, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖 Dependencies Pull requests that update a dependency file 🧹 Updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants