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(go): Added action-level and generate-level middleware. #1949

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

apascal07
Copy link
Collaborator

@apascal07 apascal07 commented Feb 12, 2025

Fixes #1945, #1940, #1727.

Checklist (if applicable):

// TODO: use a generic type alias for the above when they become available?
// Middleware is a function that wraps an action execution, similar to HTTP middleware.
// It can modify the input, output, and context, or perform side effects.
type Middleware[In, Out, Stream any] = func(ctx context.Context, input In, cb func(context.Context, Stream) error, next Func[In, Out, Stream]) (Out, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This middleware signature is similar to js (express) middleware and I'm OK with it, but in Go a more idiomatic signature might be:

type Middleware[I, O, S any] func(Func[I, O, S]) Func[I, O, S]

Similar to https://pkg.go.dev/go.ntrrg.dev/ntgo/net/http/middleware

I had it previously proposed in https://github.com/firebase/genkit/pull/429/files#diff-181ec49997af46351ae6b830a6c8883400c96f71628a4198a988e23b7d461d09

I'm OK either way, just asking if you considered it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
2 participants