Implement command-based echo app and HTTP handler

This commit is contained in:
Barak Michener 2020-09-24 14:19:31 -07:00
parent 07036afafa
commit b6b58fe2b3
6 changed files with 190 additions and 7 deletions

30
echo_app.go Normal file
View file

@ -0,0 +1,30 @@
package ussher
import (
"fmt"
"io"
"net/http"
"golang.org/x/crypto/ssh"
)
type echoHandler struct {
count int
}
func (e *echoHandler) HandleExec(conn *ssh.ServerConn, channel ssh.Channel) {
e.count += 1
io.Copy(channel, channel)
}
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
}