jsonrpc_client.go 742 B

123456789101112131415161718192021222324252627
  1. package jsonrpclite
  2. type rpcClient struct {
  3. engine RpcClientEngine
  4. }
  5. // SendString Send request string to the server.
  6. func (client *rpcClient) SendString(serviceName string, requestString string) string {
  7. return client.engine.ProcessString(serviceName, requestString)
  8. }
  9. // SendData Send request data to the server
  10. func (client *rpcClient) SendData(serviceName string, method string, params []any) string {
  11. return client.engine.ProcessData(serviceName, method, params)
  12. }
  13. //Close the client if needed
  14. func (client *rpcClient) Close() {
  15. client.engine.Close()
  16. }
  17. // NewRpcClient Create a new rpc client with engine.
  18. func NewRpcClient(engine RpcClientEngine) *rpcClient {
  19. client := new(rpcClient)
  20. client.engine = engine
  21. return client
  22. }