hoarder/queue/rpc.go

43 lines
816 B
Go
Raw Normal View History

package queue
import "errors"
2016-07-23 16:26:52 -04:00
// RPCReq contains information for communicating with the RPC server
type RPCReq struct {
method string
replyChan chan interface{}
}
2016-07-23 16:26:52 -04:00
// RPCResponse holds the response
type RPCResponse string
2016-07-23 16:26:52 -04:00
// Status contains RPC request information
type Status struct {
queueChan chan RPCReq
}
2016-07-23 16:26:52 -04:00
// RPCArgs arg information for the RPC server
type RPCArgs struct{}
2016-07-23 16:26:52 -04:00
// Downloads gets download statuses
func (s *Status) Downloads(_ RPCArgs, reply *RPCResponse) error {
replyChan := make(chan interface{})
req := RPCReq{
method: "download_status",
replyChan: replyChan,
}
s.queueChan <- req
qReply := <-replyChan
switch qReply.(type) {
case string:
*reply = RPCResponse(qReply.(string))
break
default:
return errors.New("error: unexpected return value")
}
return nil
}