diff --git a/README.md b/README.md index 4fc1732..42d2754 100755 --- a/README.md +++ b/README.md @@ -27,6 +27,13 @@ and should be easy to integrate into any existing projects. ## Middleware +Wish middlewares are analogous to those in several HTTP frameworks. +They are essentially SSH handlers that you can use to do specific tasks, +and then call the next middleware. + +Notice that middlewares are composed from first to last, +which means the last one is executed first. + ### Bubble Tea The [`bubbletea`](bubbletea) middleware makes it easy to serve any diff --git a/examples/bubbletea/main.go b/examples/bubbletea/main.go index 60e7def..3a54db5 100644 --- a/examples/bubbletea/main.go +++ b/examples/bubbletea/main.go @@ -19,8 +19,10 @@ import ( "github.com/gliderlabs/ssh" ) -const host = "localhost" -const port = 23234 +const ( + host = "localhost" + port = 23234 +) func main() { s, err := wish.NewServer( @@ -56,7 +58,7 @@ func main() { // You can wire any Bubble Tea model up to the middleware with a function that // handles the incoming ssh.Session. Here we just grab the terminal info and // pass it to the new model. You can also return tea.ProgramOptions (such as -// teaw.WithAltScreen) on a session by session basis +// tea.WithAltScreen) on a session by session basis. func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) { pty, _, active := s.Pty() if !active { diff --git a/examples/bubbleteaprogram/main.go b/examples/bubbleteaprogram/main.go index c43016e..4beb282 100644 --- a/examples/bubbleteaprogram/main.go +++ b/examples/bubbleteaprogram/main.go @@ -20,8 +20,10 @@ import ( "github.com/muesli/termenv" ) -const host = "localhost" -const port = 23234 +const ( + host = "localhost" + port = 23234 +) func main() { s, err := wish.NewServer( @@ -61,10 +63,8 @@ func myCustomBubbleteaMiddleware() wish.Middleware { p := tea.NewProgram(m, opts...) go func() { for { - select { - case <-time.After(1 * time.Second): - p.Send(timeMsg(time.Now())) - } + <-time.After(1 * time.Second) + p.Send(timeMsg(time.Now())) } }() return p @@ -73,7 +73,7 @@ func myCustomBubbleteaMiddleware() wish.Middleware { pty, _, active := s.Pty() if !active { fmt.Println("no active terminal, skipping") - s.Exit(1) + _ = s.Exit(1) return nil } m := model{ diff --git a/examples/git/main.go b/examples/git/main.go index 4a62ad2..c54dab6 100644 --- a/examples/git/main.go +++ b/examples/git/main.go @@ -19,9 +19,11 @@ import ( "github.com/gliderlabs/ssh" ) -const port = 23233 -const host = "localhost" -const repoDir = ".repos" +const ( + port = 23233 + host = "localhost" + repoDir = ".repos" +) type app struct { access gm.AccessLevel diff --git a/options.go b/options.go index 21b1464..6cf4f91 100644 --- a/options.go +++ b/options.go @@ -35,6 +35,7 @@ func WithVersion(version string) ssh.Option { // WithMiddleware composes the provided Middleware and return a ssh.Option. // This useful if you manually create an ssh.Server and want to set the // Server.Handler. +// // Notice that middlewares are composed from first to last, which means the last one is executed first. func WithMiddleware(mw ...Middleware) ssh.Option { return func(s *ssh.Server) error {