Skip to content

Commit e77991d

Browse files
authored
docs(codec): remove factory from ProtoCodec (#108)
* docs(codec): switch ProtoCodec docs from factory to prototype Update README and docs to reflect the new `NewProtoCodec[T, U](prototype T)` constructor signature, replacing references to `ProtoRequestFactory` and factory functions with a non-nil request prototype example. This aligns documentation with current API behavior and clarifies that the prototype is used to allocate fresh request messages for unmarshaling without reflection.docs(codec): switch ProtoCodec docs from factory to prototype Update README and docs to reflect the new `NewProtoCodec[T, U](prototype T)` constructor signature, replacing references to `ProtoRequestFactory` and factory functions with a non-nil request prototype example. This aligns documentation with current API behavior and clarifies that the prototype is used to allocate fresh request messages for unmarshaling without reflection. * feat(codec)!: remove prototype arg from NewProtoCodec Simplify `ProtoCodec` construction by inferring the request message type from generic `T` instead of requiring a non-nil prototype parameter. This reduces boilerplate while still allowing fresh request allocation without reflection. Also update README/docs/examples to reflect the new API and bump GitHub Actions Go versions to `1.26.1` for tests, linting, benchmarks, and example builds. BREAKING CHANGE: `codec.NewProtoCodec[T, U](prototype T)` is now `codec.NewProtoCodec[T, U]()`.feat(codec)!: remove prototype arg from NewProtoCodec Simplify `ProtoCodec` construction by inferring the request message type from generic `T` instead of requiring a non-nil prototype parameter. This reduces boilerplate while still allowing fresh request allocation without reflection. Also update README/docs/examples to reflect the new API and bump GitHub Actions Go versions to `1.26.1` for tests, linting, benchmarks, and example builds. BREAKING CHANGE: `codec.NewProtoCodec[T, U](prototype T)` is now `codec.NewProtoCodec[T, U]()`.
1 parent 41d9e05 commit e77991d

File tree

9 files changed

+62
-77
lines changed

9 files changed

+62
-77
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
go-version: ['1.24']
15+
go-version: ['1.26.1']
1616
os: [ubuntu-latest, macos-latest, windows-latest]
1717
fail-fast: true
1818

@@ -60,7 +60,7 @@ jobs:
6060
- name: Set up Go
6161
uses: actions/setup-go@v4
6262
with:
63-
go-version: '1.24'
63+
go-version: '1.26.1'
6464
cache: true
6565

6666
- name: Install golangci-lint
@@ -74,7 +74,7 @@ jobs:
7474
runs-on: ubuntu-latest
7575
strategy:
7676
matrix:
77-
go-version: ['1.24']
77+
go-version: ['1.26.1']
7878
os: [ubuntu-latest, macos-latest, windows-latest]
7979

8080
steps:
@@ -100,7 +100,7 @@ jobs:
100100
- name: Set up Go
101101
uses: actions/setup-go@v4
102102
with:
103-
go-version: '1.24'
103+
go-version: '1.26.1'
104104
cache: true
105105

106106
- name: Run benchmarks
@@ -116,7 +116,7 @@ jobs:
116116
- name: Set up Go
117117
uses: actions/setup-go@v4
118118
with:
119-
go-version: '1.24'
119+
go-version: '1.26.1'
120120
cache: true
121121

122122
- name: Build simple example

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,14 +1411,10 @@ codec.NewJSONCodec[T, U]() *codec.JSONCodec[T, U]
14111411

14121412
### ProtoCodec
14131413

1414-
Uses Protocol Buffers for marshaling and unmarshaling. Requires a factory function to create new request message instances without reflection.
1414+
Uses Protocol Buffers for marshaling and unmarshaling. It allocates fresh request messages without reflection.
14151415

14161416
```go
1417-
// Define a factory function for your specific proto message type (e.g., *MyProto)
1418-
myProtoFactory := func() *pb.MyProto { return &pb.MyProto{} } // Use generated type
1419-
1420-
// Pass the factory to the constructor
1421-
codec.NewProtoCodec[T, U](myProtoFactory) *codec.ProtoCodec[T, U] // T must match factory return type
1417+
codec.NewProtoCodec[T, U]() *codec.ProtoCodec[T, U]
14221418
```
14231419

14241420
### Codec Interface

docs/codecs.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,17 @@ route := router.RouteConfig[MyRequest, MyResponse]{
6060

6161
Handles Protocol Buffers encoding and decoding using Google's `protobuf` libraries (e.g., `google.golang.org/protobuf/proto`).
6262

63-
**Important:** Due to the nature of Protocol Buffers, the `ProtoCodec` requires a factory function (`codec.ProtoRequestFactory`) when being constructed. This function must return a new, zero-value instance of the specific *request* proto message type (`T`). This is needed internally to provide a concrete type for unmarshaling without relying on reflection.
63+
**Important:** `ProtoCodec` infers the concrete request message type from `T`, so it can allocate fresh zero-value messages for unmarshaling without reflection.
6464

6565
```go
6666
import (
6767
"github.com/Suhaibinator/SRouter/pkg/codec"
6868
pb "path/to/your/generated/proto/package" // Import your generated proto package
6969
)
7070

71-
// Define the factory function for your request proto message type
72-
// It must return the specific pointer type (e.g., *pb.MyRequestProto)
73-
var myRequestFactory = func() *pb.MyRequestProto {
74-
return &pb.MyRequestProto{}
75-
}
76-
77-
// Create a new Proto codec, providing the factory function
71+
// Create a new Proto codec.
7872
// T is *pb.MyRequestProto, U is *pb.MyResponseProto (or appropriate response type)
79-
protoCodec := codec.NewProtoCodec[*pb.MyRequestProto, *pb.MyResponseProto](myRequestFactory)
73+
protoCodec := codec.NewProtoCodec[*pb.MyRequestProto, *pb.MyResponseProto]()
8074

8175

8276
// Use it in RouteConfig
@@ -193,6 +187,6 @@ Remember to handle errors appropriately within your codec methods, potentially r
193187

194188
- **`codec.Codec[T, U]`**: Interface defining methods `NewRequest() T`, `Decode(*http.Request) (T, error)`, `DecodeBytes([]byte) (T, error)`, and `Encode(http.ResponseWriter, U) error`.
195189
- **`codec.NewJSONCodec[T, U]() *codec.JSONCodec[T, U]`**: Constructor for the built-in JSON codec.
196-
- **`codec.NewProtoCodec[T, U](factory codec.ProtoRequestFactory[T]) *codec.ProtoCodec[T, U]`**: Constructor for the built-in Protocol Buffers codec, requiring a factory function for the request type `T`.
190+
- **`codec.NewProtoCodec[T, U]() *codec.ProtoCodec[T, U]`**: Constructor for the built-in Protocol Buffers codec.
197191

198192
See the `examples/codec` directory for runnable examples using different codecs.

docs/examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Here's a brief overview of the available examples (refer to the source code and
2626
- **`/examples/trace-logging`**: Demonstrates enabling and using trace IDs for correlating logs within a request lifecycle.
2727
- **`/examples/cors-error-test`**: Demonstrates handling CORS preflight and error scenarios, including how SRouter writes CORS headers on error responses.
2828
- **`/examples/source-types`**: Shows how to use different `SourceType` options (Body, Base64QueryParameter, Base64PathParameter, etc.) for generic routes.
29-
- **`/examples/codec`**: Illustrates using different codecs, particularly `JSONCodec` and `ProtoCodec` (including the required factory function for proto).
29+
- **`/examples/codec`**: Illustrates using different codecs, particularly `JSONCodec` and `ProtoCodec`.
3030
- **`/examples/prometheus`**: Example of integrating SRouter's metrics system with Prometheus by providing a Prometheus-based implementation of the `metrics.MetricsRegistry` interface and showing how the application can expose the metrics via an HTTP handler.
3131
- **`/examples/custom-metrics`**: Demonstrates implementing a custom `metrics.MetricsRegistry` or `metrics.MetricsMiddleware`.
3232
- **`/examples/handler-error-middleware`**: Shows how middleware can access errors returned by generic handlers to make decisions (e.g., transaction rollback, custom error logging) using `scontext.GetHandlerErrorFromRequest`.

examples/codec/main.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ func main() {
6565
}, placeholderAuth, placeholderGetUserID)
6666

6767
// Instantiate the ProtoCodec (can be done once outside the handler if reused)
68-
// Create a factory function for User messages
69-
userFactory := func() *pb.User { return &pb.User{} }
70-
// Create a ProtoCodec for User messages, providing the factory
71-
protoCodec := codec.NewProtoCodec[*pb.User, *pb.User](userFactory)
68+
protoCodec := codec.NewProtoCodec[*pb.User, *pb.User]()
7269

7370
// Define the generic route configuration
7471
routeCfg := router.RouteConfig[*pb.User, *pb.User]{

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/Suhaibinator/SRouter
22

3-
go 1.24.0
3+
go 1.26.0
44

55
require (
66
github.com/julienschmidt/httprouter v1.3.0
@@ -19,8 +19,8 @@ require (
1919
github.com/jinzhu/inflection v1.0.0 // indirect
2020
github.com/jinzhu/now v1.1.5 // indirect
2121
github.com/pmezard/go-difflib v1.0.0 // indirect
22-
go.yaml.in/yaml/v2 v2.4.3 // indirect
23-
golang.org/x/text v0.32.0 // indirect
22+
go.yaml.in/yaml/v2 v2.4.4 // indirect
23+
golang.org/x/text v0.34.0 // indirect
2424
gopkg.in/yaml.v3 v3.0.1 // indirect
2525
)
2626

@@ -30,10 +30,10 @@ require (
3030
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3131
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
3232
github.com/prometheus/client_model v0.6.2
33-
github.com/prometheus/common v0.67.4 // indirect
34-
github.com/prometheus/procfs v0.19.2 // indirect
33+
github.com/prometheus/common v0.67.5 // indirect
34+
github.com/prometheus/procfs v0.20.1 // indirect
3535
go.uber.org/ratelimit v0.3.1
36-
golang.org/x/sys v0.39.0 // indirect
36+
golang.org/x/sys v0.42.0 // indirect
3737
google.golang.org/protobuf v1.36.11
3838
)
3939

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h
3434
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
3535
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
3636
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
37-
github.com/prometheus/common v0.67.4 h1:yR3NqWO1/UyO1w2PhUvXlGQs/PtFmoveVO0KZ4+Lvsc=
38-
github.com/prometheus/common v0.67.4/go.mod h1:gP0fq6YjjNCLssJCQp0yk4M8W6ikLURwkdd/YKtTbyI=
39-
github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws=
40-
github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw=
37+
github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4=
38+
github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw=
39+
github.com/prometheus/procfs v0.20.1 h1:XwbrGOIplXW/AU3YhIhLODXMJYyC1isLFfYCsTEycfc=
40+
github.com/prometheus/procfs v0.20.1/go.mod h1:o9EMBZGRyvDrSPH1RqdxhojkuXstoe4UlK79eF5TGGo=
4141
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
4242
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
4343
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
@@ -52,12 +52,12 @@ go.uber.org/ratelimit v0.3.1 h1:K4qVE+byfv/B3tC+4nYWP7v/6SimcO7HzHekoMNBma0=
5252
go.uber.org/ratelimit v0.3.1/go.mod h1:6euWsTB6U/Nb3X++xEUXA8ciPJvr19Q/0h1+oDcJhRk=
5353
go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc=
5454
go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
55-
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
56-
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
57-
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
58-
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
59-
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
60-
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
55+
go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=
56+
go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
57+
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
58+
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
59+
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
60+
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
6161
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
6262
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
6363
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

pkg/codec/proto.go

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,39 @@ import (
88
"google.golang.org/protobuf/proto"
99
)
1010

11-
// ProtoRequestFactory is a function type that creates new instances of protobuf request messages.
12-
// It returns a pointer to a type implementing proto.Message. This factory pattern is used
13-
// to avoid reflection when creating new message instances for decoding.
14-
// T must be a pointer type (e.g., *MyRequest) that implements proto.Message.
15-
type ProtoRequestFactory[T proto.Message] func() T
16-
1711
// ProtoCodec implements the Codec interface for Protocol Buffers.
1812
// It handles marshaling and unmarshaling of protobuf messages for use with generic routes.
1913
// Both T and U must be pointer types that implement proto.Message (e.g., *MyRequest, *MyResponse).
2014
type ProtoCodec[T proto.Message, U proto.Message] struct {
21-
// Factory function to create new request objects without reflection.
22-
newRequest ProtoRequestFactory[T]
15+
newRequest func() T
2316
}
2417

25-
// NewProtoCodec creates a new ProtoCodec instance with the provided request factory.
26-
// The factory function is used to create new instances of the request type without reflection.
18+
// NewProtoCodec creates a new ProtoCodec instance for protobuf request/response types.
19+
// It infers the underlying message type from T and allocates fresh zero-value messages
20+
// without reflection by using Go's new(expr) support.
2721
//
2822
// Example:
2923
//
30-
// codec := NewProtoCodec[*pb.CreateUserReq, *pb.CreateUserResp](func() *pb.CreateUserReq {
31-
// return &pb.CreateUserReq{}
32-
// })
33-
func NewProtoCodec[T proto.Message, U proto.Message](factory ProtoRequestFactory[T]) *ProtoCodec[T, U] {
24+
// codec := NewProtoCodec[*pb.CreateUserReq, *pb.CreateUserResp]()
25+
func NewProtoCodec[T interface {
26+
proto.Message
27+
*M
28+
}, U proto.Message, M any]() *ProtoCodec[T, U] {
29+
30+
var zero M
3431
return &ProtoCodec[T, U]{
35-
newRequest: factory,
32+
newRequest: func() T {
33+
return new(zero)
34+
},
3635
}
3736
}
3837

3938
// For testing purposes, we expose these variables so they can be overridden in tests
4039
var protoUnmarshal = proto.Unmarshal
4140
var protoMarshal = proto.Marshal
4241

43-
// NewRequest creates a new instance of the request protobuf message using the factory.
44-
// It implements the Codec interface. The factory pattern avoids the need for reflection
45-
// when creating new message instances.
42+
// NewRequest creates a new instance of the request protobuf message.
43+
// It implements the Codec interface.
4644
func (c *ProtoCodec[T, U]) NewRequest() T {
4745
return c.newRequest()
4846
}
@@ -52,7 +50,7 @@ func (c *ProtoCodec[T, U]) NewRequest() T {
5250
// body is closed after reading. Returns an error if the data is not valid protobuf
5351
// or doesn't match the expected message type.
5452
func (c *ProtoCodec[T, U]) Decode(r *http.Request) (T, error) {
55-
msg := c.NewRequest() // Use the factory to create a new message instance
53+
msg := c.NewRequest()
5654

5755
body, err := io.ReadAll(r.Body)
5856
if err != nil {
@@ -73,7 +71,7 @@ func (c *ProtoCodec[T, U]) Decode(r *http.Request) (T, error) {
7371
// data comes from sources other than the request body (e.g., base64-encoded
7472
// query parameters). Returns an error if the data is invalid.
7573
func (c *ProtoCodec[T, U]) DecodeBytes(data []byte) (T, error) {
76-
msg := c.NewRequest() // Use the factory to create a new message instance
74+
msg := c.NewRequest()
7775

7876
// Unmarshal directly from the provided data
7977
if err := protoUnmarshal(data, msg); err != nil {
@@ -96,5 +94,3 @@ func (c *ProtoCodec[T, U]) Encode(w http.ResponseWriter, resp U) error {
9694
_, err = w.Write(bytes)
9795
return err
9896
}
99-
100-
// newMessage function is removed as it's replaced by the factory approach.

pkg/codec/proto_test.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,30 @@ func (m *TestProtoMessage) String() string { return string(m
2121
func (m *TestProtoMessage) ProtoMessage() {}
2222
func (m *TestProtoMessage) ProtoReflect() protoreflect.Message { return nil }
2323

24-
// testProtoFactory creates a new TestProtoMessage instance.
25-
func testProtoFactory() *TestProtoMessage {
26-
return &TestProtoMessage{}
27-
}
28-
2924
// TestNewProtoCodec tests the NewProtoCodec function
3025
func TestNewProtoCodec(t *testing.T) {
31-
codec := NewProtoCodec[*TestProtoMessage, *TestProtoMessage](testProtoFactory)
26+
codec := NewProtoCodec[*TestProtoMessage, *TestProtoMessage]()
3227
if codec == nil {
3328
t.Error("Expected non-nil codec")
3429
}
3530
if codec == nil || codec.newRequest == nil {
3631
t.Error("Expected codec.newRequest to be set")
3732
}
33+
34+
req := codec.NewRequest()
35+
if req == nil {
36+
t.Fatal("Expected NewRequest to allocate a message")
37+
}
38+
39+
if req == codec.NewRequest() {
40+
t.Error("Expected NewRequest to return a distinct message instance")
41+
}
3842
}
3943

4044
// TestProtoCodecDecode tests the Decode method of ProtoCodec
4145
func TestProtoCodecDecode(t *testing.T) {
4246
// Create a codec
43-
codec := NewProtoCodec[*TestProtoMessage, *TestProtoMessage](testProtoFactory)
47+
codec := NewProtoCodec[*TestProtoMessage, *TestProtoMessage]()
4448

4549
// Create a request with test data
4650
reqBody := []byte("test data")
@@ -81,7 +85,7 @@ func TestProtoCodecDecode(t *testing.T) {
8185
// TestProtoCodecEncode tests the Encode method of ProtoCodec
8286
func TestProtoCodecEncode(t *testing.T) {
8387
// Create a codec
84-
codec := NewProtoCodec[*TestProtoMessage, *TestProtoMessage](testProtoFactory)
88+
codec := NewProtoCodec[*TestProtoMessage, *TestProtoMessage]()
8589

8690
// Create a mock implementation of proto.Marshal
8791
originalMarshal := protoMarshal
@@ -125,7 +129,7 @@ func TestProtoCodecEncode(t *testing.T) {
125129
// TestProtoCodecDecodeBytes tests the DecodeBytes method of ProtoCodec
126130
func TestProtoCodecDecodeBytes(t *testing.T) {
127131
// Create a codec
128-
codec := NewProtoCodec[*TestProtoMessage, *TestProtoMessage](testProtoFactory)
132+
codec := NewProtoCodec[*TestProtoMessage, *TestProtoMessage]()
129133

130134
// Test data (simulating decoded bytes from Base64/Base62)
131135
testBytes := []byte("test byte data")
@@ -177,7 +181,7 @@ func TestProtoCodecDecodeBytes(t *testing.T) {
177181
// TestProtoCodecDecodeErrors tests error handling in the Decode method of ProtoCodec
178182
func TestProtoCodecDecodeErrors(t *testing.T) {
179183
// Create a codec
180-
codec := NewProtoCodec[*TestProtoMessage, *TestProtoMessage](testProtoFactory)
184+
codec := NewProtoCodec[*TestProtoMessage, *TestProtoMessage]()
181185

182186
// Test Decode with read error
183187
req := httptest.NewRequest("POST", "/test", &errorReader{})
@@ -209,7 +213,7 @@ func TestProtoCodecDecodeErrors(t *testing.T) {
209213
// TestProtoCodecEncodeErrors tests error handling in the Encode method of ProtoCodec
210214
func TestProtoCodecEncodeErrors(t *testing.T) {
211215
// Create a codec
212-
codec := NewProtoCodec[*TestProtoMessage, *TestProtoMessage](testProtoFactory)
216+
codec := NewProtoCodec[*TestProtoMessage, *TestProtoMessage]()
213217

214218
// Test Encode with marshal error
215219
rr := httptest.NewRecorder()
@@ -241,5 +245,3 @@ func TestProtoCodecEncodeErrors(t *testing.T) {
241245
t.Error("Expected error when writing response fails")
242246
}
243247
}
244-
245-
// TestNewMessage is removed as the newMessage function no longer exists.

0 commit comments

Comments
 (0)