我在 Golang 中為 RPC 的服務器程序中的類型注冊了一些方法。我想從客戶端以及服務器本身使用這些方法。例如,我有一個注冊為 RPC 方法的附加方法,我想從客戶端調用它。但是我也想在同一個服務器程序中為其他一些函數調用相同的方法。有沒有辦法做到這一點?
2 回答

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