代码地址
https://github.com/mafa1993/go-micro-learn
目录为go/src/micro_server
- 增加service.go ,在里面进行rpc的注册和回调定义
- main.go 调用service.go
package main
import (
"micro_server/services"
)
func main() {
services.Run()
}
package services
import (
proto "micro_server/proto"
micro "github.com/micro/go-micro/v2"
)
// 创建所有的rpc服务
func Run() {
// 注册goods 服务
service := micro.NewService(
micro.Name("goods"),
)
service.Init()
//注册服务 参数1为micro服务
proto.RegisterGoodsServiceHandler(service.Server(), new(RequestGoods))
service.Run()
}
网友评论