mirror of
https://github.com/rwinkhart/rcw.git
synced 2026-09-05 16:47:24 -04:00
Share client code for Call()
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
package daemon
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/rpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Call connects to the RPC server and requests the passphrase.
|
||||||
|
func Call() string {
|
||||||
|
// connect to the UNIX domain socket/Windows named pipe
|
||||||
|
conn := getConn()
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
// create an RPC client using the connection
|
||||||
|
client := rpc.NewClient(conn)
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
|
// request the passphrase from the RPC server
|
||||||
|
var reply string
|
||||||
|
if err := client.Call("RCWService.GetPass", "hi", &reply); err != nil {
|
||||||
|
log.Fatalf("Error calling RCWService.GetPass: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the passphrase
|
||||||
|
return reply
|
||||||
|
}
|
||||||
@@ -5,29 +5,12 @@ package daemon
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/rpc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call connects to the RPC server and requests the passphrase.
|
func getConn() net.Conn {
|
||||||
func Call() string {
|
|
||||||
// connect to the UNIX domain socket
|
|
||||||
conn, err := net.Dial("unix", socketPath)
|
conn, err := net.Dial("unix", socketPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Dial error: %v", err)
|
log.Fatalf("Dial error: %v", err)
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
return conn
|
||||||
|
|
||||||
// create an RPC client using the connection
|
|
||||||
client := rpc.NewClient(conn)
|
|
||||||
defer client.Close()
|
|
||||||
|
|
||||||
// request the passphrase from the RPC server
|
|
||||||
var reply string
|
|
||||||
err = client.Call("RCWService.GetPass", "hi", &reply)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error calling RCWService.GetPass: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the passphrase
|
|
||||||
return reply
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,31 +4,15 @@ package daemon
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/rpc"
|
"net"
|
||||||
|
|
||||||
"github.com/Microsoft/go-winio"
|
"github.com/Microsoft/go-winio"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call connects to the RPC server and requests the passphrase.
|
func getConn() net.Conn {
|
||||||
func Call() string {
|
|
||||||
// connect to the Windows named pipe
|
|
||||||
conn, err := winio.DialPipe(socketPath, nil)
|
conn, err := winio.DialPipe(socketPath, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Dial error: %v", err)
|
log.Fatalf("Dial error: %v", err)
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
return conn
|
||||||
|
|
||||||
// create an RPC client using the connection
|
|
||||||
client := rpc.NewClient(conn)
|
|
||||||
defer client.Close()
|
|
||||||
|
|
||||||
// request the passphrase from the RPC server
|
|
||||||
var reply string
|
|
||||||
err = client.Call("RCWService.GetPass", "hi", &reply)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error calling RCWService.GetPass: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the passphrase
|
|
||||||
return reply
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user