ussher/echo_app.go

30 lines
542 B
Go

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
}