Skip to content

chore: simplify, modernize (Go 1.26), update deps#144

Merged
rustatian merged 3 commits into
masterfrom
chore/cleanup-modernize-deps
Jun 2, 2026
Merged

chore: simplify, modernize (Go 1.26), update deps#144
rustatian merged 3 commits into
masterfrom
chore/cleanup-modernize-deps

Conversation

@rustatian

@rustatian rustatian commented May 29, 2026

Copy link
Copy Markdown
Member

Applied fixes

Simplify (S) — 3 applied:

  • plugin.go: hoist cfgKey constant, eliminating two identical fmt.Sprintf("%s.%s", RootPluginName, PluginName) calls
  • plugin.go: value-range over Forbid/Allow slices (two loops)
  • plugin.go: strings.NewReplacer for path log-injection sanitization; remove dead duplicate sanitize on ext (already stripped via path.Ext)

Modernize (M) — 2 applied:

  • config.go: os.IsNotExisterrors.Is(err, fs.ErrNotExist) (Go stdlib best practice)
  • etag.go: custom appendUint helper → strconv.AppendUint; dead helper removed

Deps

go get -u all && go mod tidy run in root and tests/; go work sync run at root. No version changes — all deps were already current.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error handling and detection for missing or invalid directories in configuration validation.
  • Tests

    • Added unit tests covering configuration validation for valid paths, missing directories, and invalid file paths.
  • Refactor

    • Optimized ETag generation algorithm and simplified plugin configuration initialization logic.

- config.go: os.IsNotExist → errors.Is(fs.ErrNotExist)
- etag.go: replace custom appendUint with strconv.AppendUint; drop dead helper
- plugin.go: hoist cfgKey const (remove double Sprintf); value-range over Forbid/Allow slices; strings.NewReplacer for path sanitization; drop dead ext sanitize after ext is already clean
Copilot AI review requested due to automatic review settings May 29, 2026 12:46
@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR refactors the Roadrunner static file plugin to use standard library functions and error handling conventions. Config validation adopts the standard errors package; ETag generation replaces custom helpers with strconv.AppendUint; plugin initialization and request handling patterns are simplified through constant-based configuration keys, range-based loops, and consolidated string sanitization.

Changes

Code Modernization and Standardization

Layer / File(s) Summary
Config validation with standard error handling
config.go, config_test.go
Config validation now imports and uses github.com/roadrunner-server/errors (aliased as rrerrors) and switches to errors.Is(err, fs.ErrNotExist) for missing-directory detection. Test suite validates successful validation, missing directory errors, and file-instead-of-directory errors.
ETag generation with standard numeric conversion
etag.go
SetEtag function replaces custom appendUint helper with strconv.AppendUint for both weak and non-weak ETag construction, converting CRC32 checksums to uint64 where needed.
Plugin initialization and request handling simplification
plugin.go
Config key construction switches from fmt.Sprintf to a centralized cfgKey constant; extension initialization refactors index-based loops to range-based iteration with empty-entry skipping; request path sanitization consolidates nested strings.ReplaceAll calls and removes redundant extension sanitization before logging.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A rabbit hops through code so neat,
Where standard libs and patterns meet,
Config wrapped in error's embrace,
ETags quickened at steady pace,
Loops and strings simplified with grace.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately summarizes the main objectives: code simplifications, modernization for Go 1.26, and dependency updates across four modified files.
Description check ✅ Passed The PR description comprehensively covers all required sections: clearly lists applied fixes and modernizations with file-level details, documents dependency management, and includes test additions. All checklist items are addressed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/cleanup-modernize-deps

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.

@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Refactors the static plugin for simplification and modernization: hoists a config-key constant, switches to value-range loops, consolidates path sanitization into a package-level strings.Replacer, replaces os.IsNotExist with errors.Is(err, fs.ErrNotExist), and replaces a custom appendUint helper with strconv.AppendUint.

Changes:

  • plugin.go: introduce cfgKey constant and pathSanitizer global; cleaner range loops; remove redundant ext sanitization.
  • etag.go: use strconv.AppendUint, drop custom helper.
  • config.go: use stdlib errors.Is/fs.ErrNotExist, alias roadrunner errors as rrerrors.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
plugin.go Hoists cfgKey constant, adds shared pathSanitizer, simplifies loops.
etag.go Replaces local appendUint with strconv.AppendUint.
config.go Switches to stdlib errors.Is(fs.ErrNotExist); aliases errors import.

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

Inline strings.ReplaceAll at the single call site instead of a package-level
strings.Replacer var (+nolint:gochecknoglobals).
@rustatian rustatian self-assigned this Jun 1, 2026
Exercise the missing-directory and path-is-a-file branches of
Config.Valid, closing the codecov patch gap left by the
os.IsNotExist -> errors.Is(fs.ErrNotExist) refactor.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@config.go`:
- Line 44: The user-facing error string in the rrerrors.Errorf call is
grammatically incorrect ("does not exists"); update the message in the call
rrerrors.E(op, rrerrors.Errorf("root directory '%s' does not exists", c.Dir)) to
use "does not exist" instead, keeping the same formatting and interpolation of
c.Dir and preserving the surrounding rrerrors.E and rrerrors.Errorf usage.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2b1e4dc6-c242-46ee-9e12-8d55cdbf46fb

📥 Commits

Reviewing files that changed from the base of the PR and between a3821aa and 16f2fe5.

📒 Files selected for processing (4)
  • config.go
  • config_test.go
  • etag.go
  • plugin.go

Comment thread config.go
@rustatian
rustatian merged commit 6db0708 into master Jun 2, 2026
9 checks passed
@rustatian
rustatian deleted the chore/cleanup-modernize-deps branch June 2, 2026 20:51
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