-
Notifications
You must be signed in to change notification settings - Fork 16
Add Fiber file server command #143
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
Conversation
WalkthroughA new static file server feature is introduced, including a dedicated Go application, CLI command ( Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant FileServerApp
participant FiberServer
User->>CLI: fiber serve --flags
CLI->>FileServerApp: Parse flags, configure Options
FileServerApp->>FiberServer: Initialize Fiber app with middleware
CLI->>FiberServer: Start server (optionally with TLS)
User->>FiberServer: HTTP request (e.g., GET /)
FiberServer->>User: Serve static file or endpoint response
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
✨ Finishing Touches
🧪 Generate unit tests
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.
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 introduces a new, configurable static file server as a fiber serve subcommand, making it easier to serve web content directly from the Fiber CLI. The implementation is modular, residing in a new reusable package, and is thoroughly documented and tested.
Highlights
- New
fiber servecommand: A newfiber servesubcommand has been introduced, allowing users to easily serve static files directly from the command line. This command is highly configurable with various options for directory, address, TLS, caching, and middleware. - Reusable File Server Package: The core file server logic has been extracted into a new, reusable Go package located at
cmd/fileserver/app. This package provides aNewAppfunction that creates a Fiber application configured with static file serving and optional middleware based on provided options. - Comprehensive Documentation: The
README.mdhas been updated to include a detailed section for thefiber servecommand, listing all its available flags and their descriptions. A new dedicated guide,docs/guide/fileserver.md, has also been added to provide more in-depth usage instructions and details about the file server. - Testing and Dependency Management: New unit tests have been added for the
fileserverpackage and theserveCobra command to ensure functionality and robustness. Additionally, the Dependabot configuration has been updated to groupgithub.com/gofiber/*dependencies, streamlining future dependency updates.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 is currently in preview and 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 to provide feedback.
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
-
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. ↩
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.
Code Review
This pull request introduces a valuable fiber serve command for serving static files, with a well-structured implementation that has been moved into a reusable package. The documentation in both the README and a new guide is clear and comprehensive. The tests provide a good starting point for this new functionality.
| if o.Index != "" { | ||
| cfgStatic.IndexNames = strings.Split(o.Index, ",") | ||
| } |
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.
The current implementation for splitting the Index string by commas can lead to issues if the user provides a value with spaces, such as "index.html, index.htm". strings.Split will produce ["index.html", " index.htm"], and the static file server will look for a file named " index.htm" (with a leading space), which will likely not be found.
To handle this correctly, you should trim whitespace from each file name after splitting the string.
if o.Index != "" {
var names []string
for _, name := range strings.Split(o.Index, ",") {
names = append(names, strings.TrimSpace(name))
}
cfgStatic.IndexNames = names
}| func TestNewAppHealthEndpoints(t *testing.T) { | ||
| t.Parallel() | ||
| opts := Options{Dir: t.TempDir(), Path: "/", Health: true} | ||
| app := NewApp(opts) | ||
|
|
||
| resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, healthcheck.DefaultLivenessEndpoint, nil)) | ||
| require.NoError(t, err) | ||
| defer resp.Body.Close() | ||
| require.Equal(t, fiber.StatusOK, resp.StatusCode) | ||
| } |
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.
The test TestNewAppHealthEndpoints only verifies the liveness endpoint (/livez). For completeness, it should also test the readiness (/readyz) and startup (/startupz) endpoints that are configured in NewApp. Using a table-driven test or a loop would be a good way to cover all cases and make the test more robust.
func TestNewAppHealthEndpoints(t *testing.T) {
t.Parallel()
opts := Options{Dir: t.TempDir(), Path: "/", Health: true}
app := NewApp(opts)
endpoints := []string{
healthcheck.DefaultLivenessEndpoint,
healthcheck.DefaultReadinessEndpoint,
healthcheck.DefaultStartupEndpoint,
}
for _, endpoint := range endpoints {
t.Run(endpoint, func(t *testing.T) {
resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, endpoint, nil))
require.NoError(t, err)
defer resp.Body.Close()
require.Equal(t, fiber.StatusOK, resp.StatusCode)
})
}
}| t.Parallel() | ||
|
|
||
| if runtime.GOOS == "windows" { | ||
| t.Skip("skipping on windows") |
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.
This test is skipped on Windows without an explanation. For maintainability, it's important to document why a test is platform-specific. Please add a brief comment or update the skip message to clarify the reason (e.g., issues with file paths, permissions, etc.).
t.Skip("skipping on windows. TODO: Add reason for skipping.")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: 0
🧹 Nitpick comments (3)
cmd/fileserver/app/app_test.go (2)
17-26: Fix unchecked error return from resp.Body.Close().The test logic is well-structured and follows project conventions. However, the error return from
resp.Body.Close()should be checked.Apply this diff to handle the close error:
- defer resp.Body.Close() + defer func() { + require.NoError(t, resp.Body.Close()) + }()
28-50: Fix unchecked error return and consider Windows skip necessity.The test comprehensively validates index file serving functionality with proper assertions and cleanup. However, two minor improvements:
- The error return from
resp.Body.Close()should be checked- Consider if the Windows skip is necessary for this test
Apply this diff to handle the close error:
- defer resp.Body.Close() + defer func() { + require.NoError(t, resp.Body.Close()) + }()The Windows skip may not be necessary unless there are known filesystem-specific issues. Consider removing it unless there's a specific reason for the platform exclusion.
cmd/fileserver/app/app.go (1)
16-29: Optimize struct field alignment for better memory efficiency.The Options struct implementation is well-designed with comprehensive configuration fields. However, the field alignment can be optimized to reduce memory usage.
Apply this diff to optimize struct field alignment (reduces size from 80 to 72 bytes):
type Options struct { - Dir string - Path string - Logger bool - Cors bool - Health bool - Browse bool - Download bool - Compress bool - Cache time.Duration - MaxAge int - Index string - ByteRange bool + Dir string // 24 bytes (string header) + Path string // 24 bytes (string header) + Index string // 24 bytes (string header) + Cache time.Duration // 8 bytes (int64) + MaxAge int // 8 bytes (int/int64) + Logger bool // 1 byte + Cors bool // 1 byte + Health bool // 1 byte + Browse bool // 1 byte + Download bool // 1 byte + Compress bool // 1 byte + ByteRange bool // 1 byte + // 1 byte padding }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
.github/dependabot.ymlis excluded by!**/*.ymlgo.modis excluded by!**/*.modgo.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (8)
README.md(1 hunks)cmd/fileserver/app/app.go(1 hunks)cmd/fileserver/app/app_test.go(1 hunks)cmd/fileserver/main.go(1 hunks)cmd/root.go(1 hunks)cmd/serve.go(1 hunks)cmd/serve_test.go(1 hunks)docs/guide/fileserver.md(1 hunks)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: ReneWerner87
PR: gofiber/recipes#0
File: :0-0
Timestamp: 2024-11-26T20:05:15.793Z
Learning: For future contributions to the `gofiber/recipes` repository, ensure that the tasks outlined in `.github/CONTRIBUTING.md` are incorporated, including creating a new directory without a "fiber" prefix, adding a `README.md` with Docusaurus metadata, and updating the overview by running `make generate`.
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/server/server.go:14-16
Timestamp: 2024-11-23T19:50:41.765Z
Learning: In the `clean-code` example at `clean-code/app/server/server.go` using the Go Fiber framework, it's acceptable to omit production-level features like context usage and graceful shutdown handling to keep the example simple.
Learnt from: ReneWerner87
PR: gofiber/storage#0
File: :0-0
Timestamp: 2025-02-12T11:24:31.153Z
Learning: The storage package in gofiber/storage repository can be used independently of the Fiber web framework.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: SadikSunbul
PR: gofiber/recipes#2797
File: email-verification/main.go:26-31
Timestamp: 2025-02-07T10:18:09.439Z
Learning: In the gofiber/recipes repository, recipes should focus on demonstrating specific features clearly without production-level configurations like advanced error handling, graceful shutdown, or security middleware, as they are meant to be educational examples.
Learnt from: ReneWerner87
PR: gofiber/contrib#0
File: :0-0
Timestamp: 2024-10-16T10:04:06.328Z
Learning: The i18n functionality in the gofiber/contrib repository is being refactored from middleware to a global container to improve robustness and performance. The global container will be initialized once before setting up routes and will manage the i18n bundle and localizer map.
Learnt from: ReneWerner87
PR: gofiber/contrib#0
File: :0-0
Timestamp: 2024-07-03T11:59:00.303Z
Learning: The i18n functionality in the gofiber/contrib repository is being refactored from middleware to a global container to improve robustness and performance. The global container will be initialized once before setting up routes and will manage the i18n bundle and localizer map.
Learnt from: mdelapenya
PR: gofiber/fiber#3434
File: app.go:623-636
Timestamp: 2025-05-08T08:14:37.302Z
Learning: In the gofiber/fiber framework, service startup failures should panic rather than allowing the application to continue running with degraded functionality, as this is the agreed-upon design decision.
Learnt from: mdelapenya
PR: gofiber/fiber#3434
File: services_test.go:450-464
Timestamp: 2025-05-15T12:56:45.397Z
Learning: The `New` function in the Fiber framework automatically calls `startServices` at initialization time when services are configured, making explicit calls to `startServices` unnecessary in code that creates an App instance with `New()`.
Learnt from: sixcolors
PR: gofiber/fiber#3446
File: docs/middleware/logger.md:44-44
Timestamp: 2025-05-13T00:19:16.407Z
Learning: In documentation files for the Fiber framework, code examples are often partial and don't repeat import statements that were shown in earlier examples, focusing instead on demonstrating specific usage patterns.
cmd/serve_test.go (10)
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-07-26T21:00:12.902Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
Learnt from: efectn
PR: gofiber/fiber#3162
File: hooks_test.go:228-228
Timestamp: 2024-12-13T08:14:22.851Z
Learning: In Go test files, prefer using the `require` methods from the `testify` package for assertions instead of manual comparisons and calls to `t.Fatal` or `t.Fatalf`.
Learnt from: sixcolors
PR: gofiber/fiber#3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for `Session.Save` already exist in the `middleware/session/session_test.go` file, specifically in the `Test_Session_Save` and `Test_Session_Save_Expiration` functions.
Learnt from: sixcolors
PR: gofiber/fiber#3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for `Session.Save` already exist in the `middleware/session/session_test.go` file, specifically in the `Test_Session_Save` and `Test_Session_Save_Expiration` functions.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The `encryptcookie_test.go` file contains unit tests that validate key lengths for both `EncryptCookie` and `DecryptCookie` functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-07-02T13:29:56.992Z
Learning: The `encryptcookie_test.go` file contains unit tests that validate key lengths for both `EncryptCookie` and `DecryptCookie` functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/server/server.go:14-16
Timestamp: 2024-11-23T19:50:41.765Z
Learning: In the `clean-code` example at `clean-code/app/server/server.go` using the Go Fiber framework, it's acceptable to omit production-level features like context usage and graceful shutdown handling to keep the example simple.
docs/guide/fileserver.md (4)
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/server/server.go:14-16
Timestamp: 2024-11-23T19:50:41.765Z
Learning: In the `clean-code` example at `clean-code/app/server/server.go` using the Go Fiber framework, it's acceptable to omit production-level features like context usage and graceful shutdown handling to keep the example simple.
Learnt from: ReneWerner87
PR: gofiber/recipes#0
File: :0-0
Timestamp: 2024-11-26T20:05:15.793Z
Learning: For future contributions to the `gofiber/recipes` repository, ensure that the tasks outlined in `.github/CONTRIBUTING.md` are incorporated, including creating a new directory without a "fiber" prefix, adding a `README.md` with Docusaurus metadata, and updating the overview by running `make generate`.
Learnt from: ReneWerner87
PR: gofiber/storage#0
File: :0-0
Timestamp: 2025-02-12T11:24:31.153Z
Learning: The storage package in gofiber/storage repository can be used independently of the Fiber web framework.
Learnt from: SadikSunbul
PR: gofiber/recipes#2797
File: email-verification/main.go:26-31
Timestamp: 2025-02-07T10:18:09.439Z
Learning: In the gofiber/recipes repository, recipes should focus on demonstrating specific features clearly without production-level configurations like advanced error handling, graceful shutdown, or security middleware, as they are meant to be educational examples.
README.md (7)
Learnt from: ReneWerner87
PR: gofiber/recipes#0
File: :0-0
Timestamp: 2024-11-26T20:05:15.793Z
Learning: For future contributions to the `gofiber/recipes` repository, ensure that the tasks outlined in `.github/CONTRIBUTING.md` are incorporated, including creating a new directory without a "fiber" prefix, adding a `README.md` with Docusaurus metadata, and updating the overview by running `make generate`.
Learnt from: sixcolors
PR: gofiber/fiber#3446
File: docs/middleware/logger.md:44-44
Timestamp: 2025-05-13T00:19:16.407Z
Learning: In documentation files for the Fiber framework, code examples are often partial and don't repeat import statements that were shown in earlier examples, focusing instead on demonstrating specific usage patterns.
Learnt from: ckoch786
PR: gofiber/fiber#3230
File: docs/whats_new.md:944-951
Timestamp: 2024-12-15T19:56:45.935Z
Learning: Detailed usage examples and explanations for new methods like `RemoveRoute` and `RemoveRouteByName` are documented in `docs/api/app.md`, so it's unnecessary to duplicate them in `docs/whats_new.md`.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/server/server.go:14-16
Timestamp: 2024-11-23T19:50:41.765Z
Learning: In the `clean-code` example at `clean-code/app/server/server.go` using the Go Fiber framework, it's acceptable to omit production-level features like context usage and graceful shutdown handling to keep the example simple.
Learnt from: ReneWerner87
PR: gofiber/storage#0
File: :0-0
Timestamp: 2025-02-12T11:24:31.153Z
Learning: The storage package in gofiber/storage repository can be used independently of the Fiber web framework.
Learnt from: mdelapenya
PR: gofiber/fiber#3434
File: services_test.go:450-464
Timestamp: 2025-05-15T12:56:45.397Z
Learning: The `New` function in the Fiber framework automatically calls `startServices` at initialization time when services are configured, making explicit calls to `startServices` unnecessary in code that creates an App instance with `New()`.
cmd/fileserver/main.go (5)
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/server/server.go:14-16
Timestamp: 2024-11-23T19:50:41.765Z
Learning: In the `clean-code` example at `clean-code/app/server/server.go` using the Go Fiber framework, it's acceptable to omit production-level features like context usage and graceful shutdown handling to keep the example simple.
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/server/server.go:18-20
Timestamp: 2024-11-23T19:51:05.812Z
Learning: In the `clean-code/app/server/server.go` file, the team prefers to maintain a simple health check endpoint without additional system status information.
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/main.go:0-0
Timestamp: 2024-11-23T19:35:36.767Z
Learning: In the Go `clean-code` example (`clean-code/app/main.go`) in the `gofiber/recipes` repository, it's acceptable to omit graceful shutdown handling, as the example code prioritizes simplicity over production-level practices.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: ReneWerner87
PR: gofiber/storage#0
File: :0-0
Timestamp: 2025-02-12T11:24:31.153Z
Learning: The storage package in gofiber/storage repository can be used independently of the Fiber web framework.
cmd/fileserver/app/app_test.go (11)
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/server/server.go:18-20
Timestamp: 2024-11-23T19:51:05.812Z
Learning: In the `clean-code/app/server/server.go` file, the team prefers to maintain a simple health check endpoint without additional system status information.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-07-26T21:00:12.902Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: sixcolors
PR: gofiber/fiber#3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for `Session.Save` already exist in the `middleware/session/session_test.go` file, specifically in the `Test_Session_Save` and `Test_Session_Save_Expiration` functions.
Learnt from: sixcolors
PR: gofiber/fiber#3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for `Session.Save` already exist in the `middleware/session/session_test.go` file, specifically in the `Test_Session_Save` and `Test_Session_Save_Expiration` functions.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: efectn
PR: gofiber/fiber#3162
File: hooks_test.go:228-228
Timestamp: 2024-12-13T08:14:22.851Z
Learning: In Go test files, prefer using the `require` methods from the `testify` package for assertions instead of manual comparisons and calls to `t.Fatal` or `t.Fatalf`.
Learnt from: efectn
PR: gofiber/fiber#3162
File: app_test.go:893-895
Timestamp: 2024-11-29T12:37:27.581Z
Learning: In the `Test_App_ShutdownWithContext` function in `app_test.go`, the `clientDone` channel is used to synchronize the client's request completion before proceeding, eliminating the need for additional `time.Sleep` calls.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/server/server.go:14-16
Timestamp: 2024-11-23T19:50:41.765Z
Learning: In the `clean-code` example at `clean-code/app/server/server.go` using the Go Fiber framework, it's acceptable to omit production-level features like context usage and graceful shutdown handling to keep the example simple.
cmd/fileserver/app/app.go (7)
Learnt from: ReneWerner87
PR: gofiber/storage#0
File: :0-0
Timestamp: 2025-02-12T11:24:31.153Z
Learning: The storage package in gofiber/storage repository can be used independently of the Fiber web framework.
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/server/server.go:14-16
Timestamp: 2024-11-23T19:50:41.765Z
Learning: In the `clean-code` example at `clean-code/app/server/server.go` using the Go Fiber framework, it's acceptable to omit production-level features like context usage and graceful shutdown handling to keep the example simple.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: mdelapenya
PR: gofiber/fiber#3434
File: services_test.go:450-464
Timestamp: 2025-05-15T12:56:45.397Z
Learning: The `New` function in the Fiber framework automatically calls `startServices` at initialization time when services are configured, making explicit calls to `startServices` unnecessary in code that creates an App instance with `New()`.
Learnt from: ReneWerner87
PR: gofiber/contrib#0
File: :0-0
Timestamp: 2024-11-29T15:24:06.083Z
Learning: When customizing the Fiber context to achieve version independence, using generics in methods like `Status` and `Type` allows for fluent method chaining. Implementing a generic interface for `Ctx` on the `App` prevents class switching when registering custom contexts that use fluent methods. Providing multiple `New` methods allows users who do not wish to customize the context to continue using `fiber.New` without changes.
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/server/server.go:18-20
Timestamp: 2024-11-23T19:51:05.812Z
Learning: In the `clean-code/app/server/server.go` file, the team prefers to maintain a simple health check endpoint without additional system status information.
Learnt from: mdelapenya
PR: gofiber/fiber#3434
File: app.go:623-636
Timestamp: 2025-05-08T08:14:37.302Z
Learning: In the gofiber/fiber framework, service startup failures should panic rather than allowing the application to continue running with degraded functionality, as this is the agreed-upon design decision.
cmd/serve.go (1)
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/server/server.go:14-16
Timestamp: 2024-11-23T19:50:41.765Z
Learning: In the `clean-code` example at `clean-code/app/server/server.go` using the Go Fiber framework, it's acceptable to omit production-level features like context usage and graceful shutdown handling to keep the example simple.
🧬 Code Graph Analysis (3)
cmd/fileserver/main.go (1)
cmd/fileserver/app/app.go (2)
NewApp(32-65)Options(16-29)
cmd/fileserver/app/app_test.go (1)
cmd/fileserver/app/app.go (2)
Options(16-29)NewApp(32-65)
cmd/serve.go (1)
cmd/fileserver/app/app.go (2)
NewApp(32-65)Options(16-29)
🪛 GitHub Check: lint
cmd/fileserver/main.go
[failure] 4-4:
import 'flag' is not allowed from list 'all': flag package is only allowed in main.go (depguard)
cmd/fileserver/app/app_test.go
[failure] 44-44:
Error return value of resp.Body.Close is not checked (errcheck)
[failure] 24-24:
Error return value of resp.Body.Close is not checked (errcheck)
cmd/fileserver/app/app.go
[failure] 16-16:
fieldalignment: struct of size 80 could be 72 (govet)
🪛 GitHub Actions: golangci-lint
cmd/fileserver/app/app.go
[error] 16-16: golangci-lint (govet): struct of size 80 could be 72 (fieldalignment)
⏰ 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: Build (1.24.x, macos-13)
- GitHub Check: Build (1.24.x, windows-latest)
🔇 Additional comments (8)
cmd/root.go (1)
75-75: LGTM: Clean command registrationThe
serveCmdis properly integrated into the root command structure with logical placement between existing commands.cmd/serve_test.go (1)
11-27: Excellent test design with proper mockingThe tests demonstrate good practices:
- Dependency injection by mocking the
listenfunction- Coverage of both success and error scenarios
- Proper cleanup with defer to restore original function
- Consistent use of
testify/requirefollowing project conventionsThis approach effectively tests the command execution without actually starting a server.
cmd/fileserver/main.go (2)
4-4: Static analysis false positive - flag usage is appropriateThe static analysis warning about flag package usage is a false positive. This is a
main.gofile where the flag package is appropriately used for command-line argument parsing in a standalone application.
12-56: Well-structured standalone file server applicationThe implementation demonstrates good practices:
- Comprehensive flag definitions covering all configuration options
- Proper mapping to
fileserver.Optionsstruct- TLS support with conditional configuration
- Appropriate error handling with fatal logging
The integration with the
fileserver.NewAppfunction is clean and the server configuration properly respects all user-specified options.README.md (1)
64-97: Comprehensive and well-structured documentationThe documentation for the new
fiber servecommand is excellent:
- Clear synopsis and usage examples
- Complete enumeration of all command-line flags with defaults
- Proper reference to the detailed guide
- Consistent formatting with existing command documentation
This provides users with all necessary information to effectively use the file server functionality.
docs/guide/fileserver.md (1)
1-43: Excellent comprehensive documentation guideThis documentation demonstrates high quality:
- Proper Docusaurus frontmatter with appropriate metadata
- Clear explanation of multiple usage approaches (direct execution, binary, CLI)
- Practical examples with realistic command-line usage
- Comprehensive flag documentation with clear descriptions
- Important operational notes about TLS configuration
The guide effectively complements the README documentation and provides users with detailed guidance for using the file server functionality.
cmd/serve.go (1)
1-91: LGTM! Well-designed CLI command implementation.The implementation demonstrates excellent practices:
- Comprehensive flag configuration covering all file server options
- Clean separation of concerns using the fileserver package
- Testable design with the
listenvariable function for mocking- Proper error handling with wrapped errors
- Correct mapping of CLI flags to the Options struct
- TLS and advanced configuration support
The command provides a rich interface for configuring the file server while maintaining code clarity and testability.
cmd/fileserver/app/app.go (1)
32-65: LGTM! Excellent middleware ordering and configuration.The
NewAppfunction demonstrates best practices:
- Proper middleware ordering with recover middleware registered first
- Conditional middleware registration based on options
- Comprehensive health check endpoint setup
- Clean static file configuration with flexible index file support
- Good separation of concerns
The implementation provides a robust and configurable file server foundation.
Summary
fiber servesubcommandTesting
go mod tidygo mod vendorgo test ./...https://chatgpt.com/codex/tasks/task_e_687cd8932f308326bc5cd90a2b6cabd0
Summary by CodeRabbit
New Features
fiber serve, for serving static files with extensive configuration options.Documentation
fiber servecommand.Tests