aboutsummaryrefslogtreecommitdiff
path: root/ssh/example_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'ssh/example_test.go')
-rw-r--r--ssh/example_test.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/ssh/example_test.go b/ssh/example_test.go
index 0a6b076..3920832 100644
--- a/ssh/example_test.go
+++ b/ssh/example_test.go
@@ -16,6 +16,7 @@ import (
"os"
"path/filepath"
"strings"
+ "sync"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/terminal"
@@ -98,8 +99,15 @@ func ExampleNewServerConn() {
}
log.Printf("logged in with key %s", conn.Permissions.Extensions["pubkey-fp"])
+ var wg sync.WaitGroup
+ defer wg.Wait()
+
// The incoming Request channel must be serviced.
- go ssh.DiscardRequests(reqs)
+ wg.Add(1)
+ go func() {
+ ssh.DiscardRequests(reqs)
+ wg.Done()
+ }()
// Service the incoming Channel channel.
for newChannel := range chans {
@@ -119,16 +127,22 @@ func ExampleNewServerConn() {
// Sessions have out-of-band requests such as "shell",
// "pty-req" and "env". Here we handle only the
// "shell" request.
+ wg.Add(1)
go func(in <-chan *ssh.Request) {
for req := range in {
req.Reply(req.Type == "shell", nil)
}
+ wg.Done()
}(requests)
term := terminal.NewTerminal(channel, "> ")
+ wg.Add(1)
go func() {
- defer channel.Close()
+ defer func() {
+ channel.Close()
+ wg.Done()
+ }()
for {
line, err := term.ReadLine()
if err != nil {