Add simple test SSH server.

test/ssh
Icedream 2017-09-04 11:32:24 +02:00
parent 800d9897ff
commit cfda71a3aa
Signed by: icedream
GPG Key ID: 1573F6D8EFE4D0CF
1 changed files with 42 additions and 0 deletions

42
testssh/main.go Normal file
View File

@ -0,0 +1,42 @@
package main
import (
"bytes"
"io"
"log"
"github.com/gliderlabs/ssh"
"github.com/qpliu/qrencode-go/qrencode"
"git.icedream.tech/icedream/pixelqr/internal"
)
func main() {
greeting := "https://git.icedream.tech/icedream/pixelqr"
ssh.Handle(func(s ssh.Session) {
grid, err := qrencode.Encode(greeting, qrencode.ECLevelQ)
if err != nil {
log.Println(err)
return
}
w := new(bytes.Buffer)
err = internal.ConvertGridToUnicode(w, grid)
if err != nil {
log.Println(err)
return
}
qrs := string(w.Bytes())
io.WriteString(s, "Scan this QR code for the link to the library that generated it:\n\n")
io.WriteString(s, qrs)
io.WriteString(s, "\n\nThank you!\n")
for err == nil {
_, err = s.Read([]byte{})
}
})
log.Fatal(ssh.ListenAndServe(":2020", nil))
}