ussher/echo_app.go
2020-11-13 20:52:44 -08:00

35 lines
633 B
Go

package ussher
import (
"fmt"
"io"
"net/http"
"golang.org/x/crypto/ssh"
)
type echoHandler struct {
count int
}
func (e *echoHandler) HandleExec(_ string, conn *ssh.ServerConn, channel ssh.Channel) error {
e.count += 1
_, err := io.Copy(channel, channel)
return err
}
func (e *echoHandler) Close() error {
return nil
}
func (e *echoHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
msg := fmt.Sprintf("Hello Echo World! Calls: %d", e.count)
w.Write([]byte(msg))
}
func RegisterEchoApp(conf *Config) error {
e := &echoHandler{}
conf.SSHApps["echo"] = e
conf.HTTPMux.Handle("/echo/", e)
return nil
}