go-asink/rpc_client.go

31 lines
679 B
Go
Raw Normal View History

2013-09-04 22:02:17 -04:00
/*
Copyright (C) 2013 Aaron Lindsay <aaron@aclindsay.com>
*/
package asink
import (
2013-08-27 09:41:55 -04:00
"log"
"net"
"net/rpc"
"syscall"
)
func RPCCall(socket, method string, args interface{}, reply interface{}) error {
client, err := rpc.DialHTTP("unix", socket)
if err != nil {
if err2, ok := err.(*net.OpError); ok {
if err2.Err == syscall.ENOENT {
2013-08-27 09:41:55 -04:00
log.Fatal("The socket (" + socket + ") was not found")
} else if err2.Err == syscall.ECONNREFUSED {
2013-08-27 09:41:55 -04:00
log.Fatal("A connection was refused to " + socket + ". Please check the permissions and ensure the server is running.")
}
}
return err
}
defer client.Close()
err = client.Call(method, args, reply)
return err
}