wuYin / blog

个人博客

Home Page:https://yinzige.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

microservices-part-2-use-go-micro-and-dockerising.md syntax error

champly opened this issue · comments

博客地址:microservices-part-2-use-go-micro-and-dockerising.md
服务端的CreateConsignment和GetConsignments函数里面有点问题
原代码:
func (s *service) CreateConsignment(ctx context.Context, req *pb.Consignment, resp *pb.Response) error {
// 接收承运的货物
consignment, err := s.repo.Create(req)
if err != nil {
return err
}
resp = &pb.Response{Created: true, Consignment: consignment}
return nil
}

// 获取目前所有托运的货物
// func (s *service) GetConsignments(ctx context.Context, req *pb.GetRequest) (*pb.Response, error) {
func (s *service) GetConsignments(ctx context.Context, req *pb.GetRequest, resp *pb.Response) error {
allConsignments := s.repo.GetAll()
resp = &pb.Response{Consignments: allConsignments}
return nil
}
其中resp = &pb.Response{Created: true, Consignment: consignment}
resp = &pb.Response{Consignments: allConsignments}
对传入的req重新进行了赋值,地址发生了变化

应该用
resp.Created = true resp.Consignment = consignment

resp.Consignments = all来进行替换