Skip to content

Conversation

EwenQuim
Copy link
Member

@EwenQuim EwenQuim commented Dec 18, 2024

We're moving Fuego Context from "generic type constrained by an interface" to "interface". We're doing this for two reasons.

First, to unify Fuego framework around one unique interface that every framework will implement, with netHttpContext, ginContext, echoContext. It also allows, like Echo, to provide custom Contexts for testing, and is very flexible.

Second, because the hard thing with Generic Context type constrained by an interface is initialization. We have this ugly initialization function in serve.go called initContext.

With this PR, this unique interface is ContextWithBody[B], ContextNoBody being just an alias to ContextWithBody[any]. I wish there was a nil type, because I want to describe emptiness (nil), not "everything" (any), but Go does not allow that (that I know). When Go1.24 will go out, we will have Context[B, P] as main interface, and we'll keep ContextWithBody[B] as an alias to Context[B, any].


Release notes draft

We're changing Fuego's signature from "generic type constrained by interface" to an interface

Simply replace *fuego.ContextNoBody by fuego.ContextNoBody and *fuego.ContextWithBody by fuego.ContextWithBody

Automatically make all required changes:

For macOS (BSD sed):

find . -type f -exec sed -i '' 's/\*fuego\.ContextNoBody/fuego\.ContextNoBody/g; s/\*fuego\.ContextWithBody/fuego\.ContextWithBody/g' {} +

For Linux (GNU sed):

find . -type f -exec sed -i 's/\*fuego\.ContextNoBody/fuego\.ContextNoBody/g; s/\*fuego\.ContextWithBody/fuego\.ContextWithBody/g' {} +

This was referenced Dec 18, 2024
@EwenQuim EwenQuim changed the title BREAKING CHANGE: Remove pointer from ContextWithBody and ContextWithBody BREAKING CHANGE: Remove pointer from ContextWithBody and ContextWithBody, useInterface directly in handlers Dec 19, 2024
We're changing Fuego's signature from generic type constrained by the interface
@EwenQuim EwenQuim marked this pull request as ready for review December 19, 2024 12:54
@EwenQuim EwenQuim changed the title BREAKING CHANGE: Remove pointer from ContextWithBody and ContextWithBody, useInterface directly in handlers BREAKING CHANGE: Remove pointer from ContextNoBody and ContextWithBody, use interface directly in handlers Dec 19, 2024
@EwenQuim EwenQuim merged commit 2d3fbb8 into main Dec 19, 2024
6 of 7 checks passed
@EwenQuim EwenQuim deleted the refactored-context branch December 19, 2024 22:17
@EwenQuim EwenQuim mentioned this pull request Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants