sshrpc/example_server_test.go

35 lines
619 B
Go
Raw Normal View History

2015-05-30 17:25:21 +00:00
package sshrpc
import (
"fmt"
"io/ioutil"
"log"
"golang.org/x/crypto/ssh"
)
type ExampleServer struct{}
func (s *ExampleServer) Hello(name *string, out *string) error {
*out = fmt.Sprintf("Hello %s", *name)
return nil
}
func ExampleServer_StartServer() {
s := NewServer()
privateBytes, err := ioutil.ReadFile("id_rsa")
if err != nil {
log.Fatal("Failed to load private key (./id_rsa)")
}
private, err := ssh.ParsePrivateKey(privateBytes)
if err != nil {
log.Fatal("Failed to parse private key")
}
s.Config.AddHostKey(private)
s.Register(new(ExampleServer))
s.StartServer("localhost:2022")
}