-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Refactor static file server handler and logger (#8)
Refactor the code in staticFileServerHandler.go and logger.go to improve code organization and readability. The changes include: - Move the logger related functions to a separate file, logger.go, for better separation of concerns. - Rename the StaticFilesHandler function to NewStaticFilesHandler to follow the Go convention for constructor functions. - Extract the ServeHTTP method from the StaticFilesHandler function and move it to the StaticFilesHandler struct to improve encapsulation. - Clean up the code by removing unused imports and variables. This commit improves the maintainability and readability of the codebase.
- Loading branch information
1 parent
b5d1de7
commit fe7c839
Showing
3 changed files
with
93 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package spaserve | ||
|
||
import ( | ||
"context" | ||
"log/slog" | ||
) | ||
|
||
type servespaLogger struct { | ||
logger *slog.Logger | ||
} | ||
|
||
// newLogger creates a new logger function with the given context and logger. | ||
func newLogger(logger *slog.Logger) *servespaLogger { | ||
return &servespaLogger{logger: logger} | ||
} | ||
|
||
func (l servespaLogger) logContext(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr) { | ||
if l.logger == nil { | ||
return | ||
} | ||
l.logger.LogAttrs(ctx, level, msg, attrs...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters