-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add ability to intercept streams with middleware #93
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is a common concept in HTTP handling, though the implementation doesn't seem to quite match by introducing the requirement to implement types instead of just a function?
Also is the "SetMiddleware" a clear enough name? In the realm of terminals or GUIs I'm not sure it`s totally clear...
term.go
Outdated
@@ -497,3 +504,20 @@ func (t *Terminal) Dragged(d *fyne.DragEvent) { | |||
func (t *Terminal) DragEnd() { | |||
t.selecting = false | |||
} | |||
|
|||
// SetMiddleware sets the middleware function that will be used when creating a new terminal. | |||
// The middleware function is responsible for setting up the I/O readers and writers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way middleware is implemented it is an interface type not function.
It feels like a function would be enough to set up the interception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats the beauty of golang right?
// MiddlewareFunc is a function type that matches the signature of the
// SetupMiddleware method in the Middleware interface.
type MiddlewareFunc func(r io.Reader, w io.WriteCloser) (io.Reader, io.WriteCloser)
// SetupMiddleware allows MiddlewareFunc to satisfy the Middleware interface.
// It calls the MiddlewareFunc itself.
func (m MiddlewareFunc) SetupMiddleware(r io.Reader, w io.WriteCloser) (io.Reader, io.WriteCloser) {
return m(r, w)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess if following the http middleware / handler idea it was missing the func helper? https://pkg.go.dev/net/http#HandlerFunc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes essentially the same pattern
Sorry for the test failures, fixed on master |
Add the ability to add support for such things as zmodem and/or other stream middleware's
no worries rebased |
I think this is still niggling me - it's such a generic term that I have never heard use in stream handling or terminals before. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think that is clear now
Add the ability to add support for such things as zmodem and/or other
stream middleware's