1.TarsGo官方文档
2.TarsGo使用指南之服务端
3.TarsGo使用指南之客户端

1.安装tars,构建tars2go工具

go get github.com/TarsCloud/TarsGo/tars

cd $GOPATH/src/github.com/TarsCloud/TarsGo/tars/tools/tars2go & go build .

cp tars2go $GOPATH/bin

2.编写tars文件,如hello.tars,进行接口定义

# hello.tars
module TestApp {
    interface Hello{
        int test();
        int testHello(string sReq, out string sRsp);
    };

    interface SayHello {
        int echoHello(string name, out string greeting);
    };
};

3.使用tars2go工具编译tars文件并转成go文

tars2go --outdir=./vendor hello.tars

4.接口实现(处理业务逻辑)

# HelloImp.go
package main

type HelloImp struct {
}

// implement the test interface
func (imp *HelloImp) Test() (int32, error) {
   return 0, nil
}

// implement the testHello interface
func (imp *HelloImp) TestHello(in string, out *string) (int32, error) {
   *out = in
   return 0, nil
}

5.编译go文件生成二进制文件

cd /path/TarGo-demo & go build .

6.编写服务端配置文件,如config.conf

# config.conf
<tars>
    <application>
        <server>
            app=TestApp
            server=TestAppServer
            logpath=logs
            local=tcp -h 127.0.0.1 -p 9999 -t 3000
            <TestApp.TestAppServer.SayHelloObjAdapter>
                endpoint=tcp -h 127.0.0.1 -p 9997 -t 6000
                servant=TestApp.TestAppServer.SayHelloObj
            </TestApp.TestAppServer.SayHelloObjAdapter>

            <TestApp.TestAppServer.HelloObjAdapter>
                endpoint=tcp -h 127.0.0.1 -p 9998 -t 6000
                servant=TestApp.TestAppServer.HelloObj
            </TestApp.TestAppServer.HelloObjAdapter>
        </server>
    </application>
</tars>

7.启动服务端

./tarsgo-server --config=config.conf