-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Implement Fluent Method Chaining for Status and Type Methods Using Generics #3221
Comments
Hi, I would like to work on this issue. |
Hi, already working on it |
Okay, I will look into other issues
…On Tue, 28 Jan 2025 at 1:46 AM, RW ***@***.***> wrote:
Hi, already working on it
You are welcome to help with other issues
—
Reply to this email directly, view it on GitHub
<#3221 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AP5AMYEKNWKP5LVBSIRR7BT2M2H3LAVCNFSM6AAAAABSXKJJOSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMJWHAYDAMBXG4>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Will push my changes in a few hours |
@rishabhDev2700 maybe you can help us with the current status, we still have some errors and problems which we have to solve |
we still have the fluent interface method chaining problem package main
import (
"context"
"fmt"
)
type Service[T any] interface {
Execute() string
WithContext(ctx context.Context) Service[T]
}
type MyService struct {
ctx context.Context
}
func (m *MyService) Execute() string {
return "Executing..."
}
func (m *MyService) Special() string {
return "Special method"
}
func (m *MyService) WithContext(ctx context.Context) Service[*MyService] {
m.ctx = ctx
return m
}
func main() {
service := &MyService{}
fmt.Println(service.Special()) // OK
wrapped := service.WithContext(context.Background()) // <- self reference
if typed, ok := wrapped.(*MyService); ok { // we want it without type assertion
fmt.Println(typed.Special()) // Works with type assertion
} else {
fmt.Println("Type assertion failed")
}
} |
@ReneWerner87 I will work on it |
But use the current code changes from the existing branch |
Ok, I will ask you if there is any query
…On Mon, 10 Feb 2025 at 8:08 PM, RW ***@***.***> wrote:
But use the current code changes from the existing branch
—
Reply to this email directly, view it on GitHub
<#3221 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AP5AMYCH3CVEOKWHQERNP7T2PC2WTAVCNFSM6AAAAABSXKJJOSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNBYGE4TINJYGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@ReneWerner87 Can you please provide me some pointers on this issue. |
@rishabhDev2700 Right, the problem of recursive generics must be solved |
We propose implementing the fluent concept for the methods
Status
andType
in the Fiber framework using generics, as discussed in the following articles:Background:
Using generics allows for method chaining by having methods return a generic interface type, similar to the
self
keyword in other languages. Since Go does not have aself
keyword, generics provide a feasible alternative without significant language changes.Proposal:
Modify the
Context
Interface:Change methods like
Status
andType
to return a generic interface instead of a concrete type.This enables fluent method chaining while maintaining type safety and flexibility.
Implement a Generic
Ctx
Interface onApp
:Ctx
on theApp
.Provide Multiple
New
Methods:fiber.New
without any changes.Benefits:
References:
Requested by: @ReneWerner87
The text was updated successfully, but these errors were encountered: