gRPC-DLang - gRPC 的 D 语言实现


Apache
跨平台
D语言

软件简介

gRPC-DLang 是使用 D 语言开发的 gRPC 实现,基于 hunt-
http
的 http 2.0 实现。

服务端示例代码:

import grpc;

import helloworld.helloworld;
import helloworld.helloworldrpc;

class GreeterImpl : GreeterBase
{
    override Status SayHello(HelloRequest request , ref HelloReply reply)
    {
        reply.message = "hello " ~ request.name;
        return Status.OK;
    }
}

void main()
{
    string host = "127.0.0.1";
    ushort port = 5001;

    auto server = new Server();
    server.listen(host , port);
    server.register( new GreeterImpl());
    server.start();
}

客户端示例代码:

import grpc;

import helloworld.helloworld;
import helloworld.helloworldrpc;

import std.stdio;

void main()
{
    auto channel = new Channel("127.0.0.1" , 5001);
    GreeterClient client = new GreeterClient(channel);

    auto request = new HelloRequest();
    request.name = "test";

    HelloReply reply = client.SayHello(request);

    if(reply !is null)
    {
       writeln(reply.message);
    }
}