Skip to content

Commit ff6e18e

Browse files
authored
Merge pull request #37 from strvcom/feat/http-expose-response-writer
feat(http): make ResponseWriter public
2 parents 6059f50 + f1eeffa commit ff6e18e

File tree

6 files changed

+13
-12
lines changed

6 files changed

+13
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ How to release a new version:
1010
### Removed
1111
- 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"`)
1212

13+
### Changed
14+
- ResponseWriter has been moved to the `http` package and is no longer private.
15+
1316
## [0.7.1] - 2024-07-11
1417
### Changed
1518
- Canceling `Server.Run()` context no longer cancels requests base context.

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ When you are creating a [feature request](#how-do-i-submit-a-feature-request), p
2929
Planned features are tracked as [GitHub issues](https://github.com/strvcom/strv-backend-go-net/issues).
3030
Create an issue on the repository and provide the following information:
3131
- Use a clear and descriptive title for the issue to identify the feature request.
32-
- Provide a step-by-step description of the feature request in as much details as possible.
32+
- Provide a step-by-step description of the feature request in as many details as possible.
3333
- Provide specific examples to demonstrate the usage of the feature. Include copy/pasteable snippets which you use in those examples, as Markdown code blocks.
3434
- Describe the current behavior and explain which behavior you expected to see instead and why.
3535
- Explain why this feature would be useful to most users.
@@ -71,4 +71,4 @@ feat(ci): add configuration for linter
7171
- Prepare changes in a new branch of your forked repository.
7272
- Merge request's title should contain a link to a GitHub issue and should be named descriptively.
7373
- The description must contain a functional description of the changes.
74-
- Each change should be thoroughly documented in the CHANGELOG.md (which can be used in the PR description).
74+
- Each change should be thoroughly documented in the CHANGELOG.md (which can be used in the PR description).

http/middleware.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"go.strv.io/net"
10-
"go.strv.io/net/internal"
1110
)
1211

1312
const (
@@ -65,9 +64,9 @@ func RecoverMiddleware(l *slog.Logger, opts ...RecoverMiddlewareOption) func(htt
6564
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
6665
defer func() {
6766
if re := recover(); re != nil {
68-
rw, ok := w.(*internal.ResponseWriter)
67+
rw, ok := w.(*ResponseWriter)
6968
if !ok {
70-
rw = internal.NewResponseWriter(w, l)
69+
rw = NewResponseWriter(w, l)
7170
}
7271

7372
rw.SetPanicObject(re)
@@ -101,9 +100,9 @@ func RecoverMiddleware(l *slog.Logger, opts ...RecoverMiddlewareOption) func(htt
101100
func LoggingMiddleware(l *slog.Logger) func(http.Handler) http.Handler {
102101
return func(next http.Handler) http.Handler {
103102
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
104-
rw, ok := w.(*internal.ResponseWriter)
103+
rw, ok := w.(*ResponseWriter)
105104
if !ok {
106-
rw = internal.NewResponseWriter(w, l)
105+
rw = NewResponseWriter(w, l)
107106
}
108107

109108
requestStart := time.Now()
@@ -156,7 +155,7 @@ func (r RequestData) LogValue() slog.Value {
156155
}
157156

158157
// withRequestData returns slog with filled fields.
159-
func withRequestData(l *slog.Logger, rw *internal.ResponseWriter, rd RequestData) *slog.Logger {
158+
func withRequestData(l *slog.Logger, rw *ResponseWriter, rd RequestData) *slog.Logger {
160159
errorObject := rw.ErrorObject()
161160
panicObject := rw.PanicObject()
162161
if errorObject != nil {

http/response.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package http
33
import (
44
"fmt"
55
"net/http"
6-
7-
"go.strv.io/net/internal"
86
)
97

108
type ResponseOptions struct {
@@ -79,7 +77,7 @@ func WriteErrorResponse(
7977
return fmt.Errorf("response encoding: %w", err)
8078
}
8179

82-
if rw, ok := w.(*internal.ResponseWriter); ok {
80+
if rw, ok := w.(*ResponseWriter); ok {
8381
rw.SetErrorObject(o.Err)
8482
}
8583

internal/responsewriter.go renamed to http/responsewriter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package internal
1+
package http
22

33
import (
44
"bufio"

http/server_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/stretchr/testify/assert"
13+
1314
"go.strv.io/net/internal"
1415
)
1516

0 commit comments

Comments
 (0)