我在 Golang 中為 RPC 的服務(wù)器程序中的類型注冊(cè)了一些方法。我想從客戶端以及服務(wù)器本身使用這些方法。例如,我有一個(gè)注冊(cè)為 RPC 方法的附加方法,我想從客戶端調(diào)用它。但是我也想在同一個(gè)服務(wù)器程序中為其他一些函數(shù)調(diào)用相同的方法。有沒(méi)有辦法做到這一點(diǎn)?
2 回答

守候你守候我
TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超10個(gè)贊
我必須自己做這件事。這是一個(gè)人為的例子,展示了我在我的案例中所做的:
這是RPC函數(shù)...
func (server *Server) RemoteGoroutineCount(request GoroutineCountsRequest, response *GoroutineCountsResponse) error {
response.Count = runtime.NumGoroutine()
return nil
}
現(xiàn)在,如果我想在本地調(diào)用它,我可以這樣做
req := GoroutineCountsRequest{}
res := &GorouteCountsResponse{}
s := &Server{}
err := s.RemoteGoroutineCount(req, res)
// handle error
// Now res has your filled in response
res.NumGoroutines
- 2 回答
- 0 關(guān)注
- 308 瀏覽
添加回答
舉報(bào)
0/150
提交
取消