-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathmain.go
51 lines (43 loc) · 1.24 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"errors"
"net"
"github.com/charmbracelet/log"
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
"github.com/charmbracelet/wish/logging"
)
const (
host = "localhost"
port = "23234"
)
func main() {
srv, err := wish.NewServer(
// The address the server will listen to.
wish.WithAddress(net.JoinHostPort(host, port)),
// The SSH server need its own keys, this will create a keypair in the
// given path if it doesn't exist yet.
// By default, it will create an ED25519 key.
wish.WithHostKeyPath(".ssh/id_ed25519"),
// Middlewares do something on a ssh.Session, and then call the next
// middleware in the stack.
wish.WithMiddleware(
func(next ssh.Handler) ssh.Handler {
return func(sess ssh.Session) {
wish.Println(sess, "Hello, world!")
next(sess)
}
},
// The last item in the chain is the first to be called.
logging.Middleware(),
),
)
if err != nil {
log.Error("Could not start server", "error", err)
}
log.Info("Starting SSH server", "host", host, "port", port)
if err = srv.ListenAndServe(); err != nil && !errors.Is(err, ssh.ErrServerClosed) {
// We ignore ErrServerClosed because it is expected.
log.Error("Could not start server", "error", err)
}
}