Implement command-based echo app and HTTP handler
This commit is contained in:
parent
07036afafa
commit
b6b58fe2b3
6 changed files with 190 additions and 7 deletions
30
echo_app.go
Normal file
30
echo_app.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue