TarsGo 开源项目教程

TarsGo 开源项目教程

TarsGoA high performance microservice framework in golang. A linux foundation project.项目地址:https://gitcode.com/gh_mirrors/ta/TarsGo

1. 项目的目录结构及介绍

TarsGo 项目的目录结构如下:

TarsGo/
├── app
│   ├── demo
│   │   ├── demo.go
│   │   ├── demo_imp.go
│   │   └── tars-protocol
│   │       └── Demo
│   │           ├── Demo.tars
│   │           └── Demo_IF.go
│   └── tars-protocol
│       └── tars
│           ├── tars.tars
│           └── tars_IF.go
├── build
│   └── makefile
├── client
│   └── client.go
├── config.conf
├── go.mod
├── go.sum
├── main.go
├── makefile
└── README.md

目录结构介绍

  • app/: 包含应用程序的代码。
    • demo/: 示例应用程序的代码。
      • demo.go: 示例应用程序的主文件。
      • demo_imp.go: 示例应用程序的实现文件。
      • tars-protocol/Demo/: 示例应用程序的协议文件。
        • Demo.tars: 协议定义文件。
        • Demo_IF.go: 生成的协议接口文件。
    • tars-protocol/tars/: Tars 框架的基础协议文件。
      • tars.tars: 基础协议定义文件。
      • tars_IF.go: 生成的基础协议接口文件。
  • build/: 包含构建相关的文件。
    • makefile: 构建脚本。
  • client/: 客户端示例代码。
    • client.go: 客户端主文件。
  • config.conf: 配置文件。
  • go.modgo.sum: Go 模块文件。
  • main.go: 项目启动文件。
  • makefile: 项目构建脚本。
  • README.md: 项目说明文档。

2. 项目的启动文件介绍

项目的启动文件是 main.go。这个文件负责启动 TarsGo 服务。以下是 main.go 的主要内容:

package main

import (
    "github.com/TarsCloud/TarsGo/tars"
    "app/demo"
)

func main() {
    imp := new(demo.DemoImp)
    app := new(demo.Demo)
    cfg := tars.GetServerConfig()
    app.AddServant(imp, cfg.App+"."+cfg.Server+".DemoObj")
    tars.Run()
}

启动文件介绍

  • main 函数:项目的入口点。
  • imp:服务实现对象。
  • app:服务对象。
  • cfg:获取服务器配置。
  • app.AddServant:添加服务实现到服务对象。
  • tars.Run:启动 Tars 服务。

3. 项目的配置文件介绍

项目的配置文件是 config.conf。这个文件包含了 TarsGo 服务的配置信息。以下是 config.conf 的主要内容:

<tars>
    <application>
        # 应用名称
        app=TestApp
        # 服务名称
        server=HelloServer
        # 服务端口
        local=tcp -h 127.0.0.1 -p 18600 -t 3000
        # 日志级别
        logLevel=DEBUG
    </application>
</tars>

配置文件介绍

  • <tars>:Tars 配置的根节点。
  • <application>:应用配置节点。
    • app:应用名称。
    • server:服务名称。
    • local:服务监听的地址和端口。
    • logLevel:日志级别。

以上是 TarsGo 开源项目的目录结构、启动文件和配置文件的详细介绍。希望这份教程能帮助你更好地理解和使用 TarsGo 项目。

TarsGoA high performance microservice framework in golang. A linux foundation project.项目地址:https://gitcode.com/gh_mirrors/ta/TarsGo

  • 5
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

诸锬泽Jemima

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值