Skip to content
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

feat(http): make ResponseWriter public #37

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ How to release a new version:
### Removed
- package `http/param`: can no longer change the tag value prefix the parser reacts to (e.g. from `param:"query=q"` to `param:"myPrefix=q"`)

### Changed
- ResponseWriter has been moved to the `http` package and is no longer private.

## [0.7.1] - 2024-07-11
### Changed
- Canceling `Server.Run()` context no longer cancels requests base context.
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ When you are creating a [feature request](#how-do-i-submit-a-feature-request), p
Planned features are tracked as [GitHub issues](https://github.com/strvcom/strv-backend-go-net/issues).
Create an issue on the repository and provide the following information:
- Use a clear and descriptive title for the issue to identify the feature request.
- Provide a step-by-step description of the feature request in as much details as possible.
- Provide a step-by-step description of the feature request in as many details as possible.
- Provide specific examples to demonstrate the usage of the feature. Include copy/pasteable snippets which you use in those examples, as Markdown code blocks.
- Describe the current behavior and explain which behavior you expected to see instead and why.
- Explain why this feature would be useful to most users.
Expand Down Expand Up @@ -71,4 +71,4 @@ feat(ci): add configuration for linter
- Prepare changes in a new branch of your forked repository.
- Merge request's title should contain a link to a GitHub issue and should be named descriptively.
- The description must contain a functional description of the changes.
- Each change should be thoroughly documented in the CHANGELOG.md (which can be used in the PR description).
- Each change should be thoroughly documented in the CHANGELOG.md (which can be used in the PR description).
11 changes: 5 additions & 6 deletions http/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"go.strv.io/net"
"go.strv.io/net/internal"
)

const (
Expand Down Expand Up @@ -65,9 +64,9 @@ func RecoverMiddleware(l *slog.Logger, opts ...RecoverMiddlewareOption) func(htt
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if re := recover(); re != nil {
rw, ok := w.(*internal.ResponseWriter)
rw, ok := w.(*ResponseWriter)
if !ok {
rw = internal.NewResponseWriter(w, l)
rw = NewResponseWriter(w, l)
}

rw.SetPanicObject(re)
Expand Down Expand Up @@ -101,9 +100,9 @@ func RecoverMiddleware(l *slog.Logger, opts ...RecoverMiddlewareOption) func(htt
func LoggingMiddleware(l *slog.Logger) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rw, ok := w.(*internal.ResponseWriter)
rw, ok := w.(*ResponseWriter)
if !ok {
rw = internal.NewResponseWriter(w, l)
rw = NewResponseWriter(w, l)
}

requestStart := time.Now()
Expand Down Expand Up @@ -156,7 +155,7 @@ func (r RequestData) LogValue() slog.Value {
}

// withRequestData returns slog with filled fields.
func withRequestData(l *slog.Logger, rw *internal.ResponseWriter, rd RequestData) *slog.Logger {
func withRequestData(l *slog.Logger, rw *ResponseWriter, rd RequestData) *slog.Logger {
errorObject := rw.ErrorObject()
panicObject := rw.PanicObject()
if errorObject != nil {
Expand Down
4 changes: 1 addition & 3 deletions http/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package http
import (
"fmt"
"net/http"

"go.strv.io/net/internal"
)

type ResponseOptions struct {
Expand Down Expand Up @@ -79,7 +77,7 @@ func WriteErrorResponse(
return fmt.Errorf("response encoding: %w", err)
}

if rw, ok := w.(*internal.ResponseWriter); ok {
if rw, ok := w.(*ResponseWriter); ok {
rw.SetErrorObject(o.Err)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/responsewriter.go → http/responsewriter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package http

import (
"bufio"
Expand Down
1 change: 1 addition & 0 deletions http/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/stretchr/testify/assert"

"go.strv.io/net/internal"
)

Expand Down
Loading