https://github.com/sdttttt/go-tds
A minimal micro-service framework implementation. (including registry)
https://github.com/sdttttt/go-tds
framework golang grpc microservice rpc
Last synced: 1 day ago
JSON representation
A minimal micro-service framework implementation. (including registry)
- Host: GitHub
- URL: https://github.com/sdttttt/go-tds
- Owner: sdttttt
- License: mit
- Created: 2020-03-16T13:13:49.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-01-30T08:41:40.000Z (about 4 years ago)
- Last Synced: 2025-08-15T12:28:53.325Z (8 months ago)
- Topics: framework, golang, grpc, microservice, rpc
- Language: Go
- Homepage:
- Size: 139 KB
- Stars: 1
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go-tds

[](https://goreportcard.com/report/github.com/sdttttt/go-tds)
[](https://codebeat.co/projects/github-com-sdttttt-go-tds-master)
[](https://codecov.io/gh/sdttttt/go-tds) [](https://gitter.im/go-tds/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
一个微服务验证框架,使用go编写.
实现最小单位的服务注册,调度,调用等功能。
# Example
### Hub
```shell
git clone https://github.com/sdttttt/go-tds.git
```
```
go build -v -o hub
./hub
```
```yaml
hub:
address: localhost
port: 1234 // 默认在1234端口
checkSurvivalTime: 120 // 检查服务生存间隔时间 (Unit: Seconds)
```
### Provider Service
```yaml
hub:
address: localhost
port: 1234
self:
address: localhost
port: 5555
survivalTime: 45 // 设置服务的心跳间隔, 这个值得小于Hub上的服务检查时间间隔
```
```go
package main
import (
"log"
"net"
"net/http"
"net/rpc"
"github.com/sdttttt/go-tds/trpc"
)
type API struct{}
func (a *API) Hello(in int, out *int) error {
*out = 100
return nil
}
func main() {
// 注册填入您的服务名即可
trpc.Register("API.Hello")
api := new(API)
// 在这里注册它
rpc.Register(api)
l, err := net.Listen("tcp", ":4321")
if err != nil {
log.Println(err)
return
}
rpc.HandleHTTP()
go http.Serve(l, nil)
select {}
}
```
### Customer
```yaml
hub:
address: localhost
port: 1234
```
```go
package main
import (
"log"
"github.com/sdttttt/go-tds/trpc"
)
func main() {
var one int = 1
var two int
// 服务端如果使用golang的RPC
// go-tds提供了简单便利的库, trpc
err := trpc.Call("API.Hello", one, &two)
if err != nil {
log.Fatalln(err)
}
println(two)
}
```
```shell
localhost : 4321
API.Hello (0x88c720,0xc000136030) (0x8770e0,0xc000136008)
1
```