报错 {"id":"go.micro.client","code":500,"detail":"service hello.service: not found","status":"Internal Server Error"}
是这样最近在学习微服务 看了好多课程踩了好多的坑
版本兼容性搞完了结果还是出现了问题
希望哪位路过的大佬帮忙瞅瞅 看一下啥问题了
服务端(可以启动)
```
package main
import (
pb "GoTest/newmicro/proto"
"context"
"fmt"
"github.com/micro/go-micro"
)
type Cap struct {
}
func (c *Cap) SayHello(ctx context.Context, Requ *pb.SayRequest, Resp *pb.SayResponse) error {
Resp.Msg = "太阳当空照" + Requ.Message
return nil
}
func main() {
service := micro.NewService(
micro.Name("hello.service"),
)
service.Init()
//注册服务
pb.RegisterCapHandler(service.Server(), new(Cap))
if err := service.Run(); err != nil {
fmt.Println()
}
}
```
客户端(报错500)
```
package main
import (
pb "GoTest/newmicro/proto"
"context"
"fmt"
"github.com/micro/go-micro"
"github.com/micro/go-micro/registry"
"github.com/micro/go-micro/registry/mdns"
)
func main() {
reg := mdns.NewRegistry(func(op *registry.Options) {
op.Addrs = []string{
"127.0.0.1:8500",
}
})
service := micro.NewService(
micro.Name("hello.client"),
)
service.Init(micro.Registry(reg))
capPb := pb.NewCapService("hello.service", service.Client())
res, err := capPb.SayHello(context.TODO(), &pb.SayRequest{Message: "哈哈哈哈哈哈"})
if err != nil {
fmt.Println("报错", err)
return
}
fmt.Println(res.Msg)
}
```
go mod
```
module GoTest/newmicro
go 1.14
require (
github.com/golang/protobuf v1.4.3
github.com/micro/go-micro v1.18.0
github.com/micro/go-micro/v2 v2.9.1
google.golang.org/protobuf v1.25.0
)
replace google.golang.org/grpc => google.golang.org/grpc v1.26.0
```