2021-01-19 22:08:06 +03:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2021-01-29 15:01:10 +03:00
|
|
|
pb "github.com/unistack-org/micro-register-service/v3/proto"
|
|
|
|
"github.com/unistack-org/micro/v3/register"
|
2021-01-19 22:08:06 +03:00
|
|
|
)
|
|
|
|
|
2021-01-29 15:01:10 +03:00
|
|
|
func ToProto(s *register.Service) *pb.Service {
|
2021-01-19 22:08:06 +03:00
|
|
|
endpoints := make([]*pb.Endpoint, 0, len(s.Endpoints))
|
|
|
|
for _, ep := range s.Endpoints {
|
|
|
|
endpoints = append(endpoints, &pb.Endpoint{
|
|
|
|
Name: ep.Name,
|
2021-04-20 23:43:41 +03:00
|
|
|
Request: ep.Request,
|
|
|
|
Response: ep.Response,
|
2021-01-19 22:08:06 +03:00
|
|
|
Metadata: ep.Metadata,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
nodes := make([]*pb.Node, 0, len(s.Nodes))
|
|
|
|
|
|
|
|
for _, node := range s.Nodes {
|
|
|
|
nodes = append(nodes, &pb.Node{
|
|
|
|
Id: node.Id,
|
|
|
|
Address: node.Address,
|
|
|
|
Metadata: node.Metadata,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pb.Service{
|
|
|
|
Name: s.Name,
|
|
|
|
Version: s.Version,
|
|
|
|
Metadata: s.Metadata,
|
|
|
|
Endpoints: endpoints,
|
|
|
|
Nodes: nodes,
|
|
|
|
Options: new(pb.Options),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-29 15:01:10 +03:00
|
|
|
func ToService(s *pb.Service) *register.Service {
|
|
|
|
endpoints := make([]*register.Endpoint, 0, len(s.Endpoints))
|
2021-01-19 22:08:06 +03:00
|
|
|
for _, ep := range s.Endpoints {
|
2021-01-29 15:01:10 +03:00
|
|
|
endpoints = append(endpoints, ®ister.Endpoint{
|
2021-01-19 22:08:06 +03:00
|
|
|
Name: ep.Name,
|
2021-04-20 23:43:41 +03:00
|
|
|
Request: ep.Request,
|
|
|
|
Response: ep.Response,
|
2021-01-19 22:08:06 +03:00
|
|
|
Metadata: ep.Metadata,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-29 15:01:10 +03:00
|
|
|
nodes := make([]*register.Node, 0, len(s.Nodes))
|
2021-01-19 22:08:06 +03:00
|
|
|
for _, node := range s.Nodes {
|
2021-01-29 15:01:10 +03:00
|
|
|
nodes = append(nodes, ®ister.Node{
|
2021-01-19 22:08:06 +03:00
|
|
|
Id: node.Id,
|
|
|
|
Address: node.Address,
|
|
|
|
Metadata: node.Metadata,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-29 15:01:10 +03:00
|
|
|
return ®ister.Service{
|
2021-01-19 22:08:06 +03:00
|
|
|
Name: s.Name,
|
|
|
|
Version: s.Version,
|
|
|
|
Metadata: s.Metadata,
|
|
|
|
Endpoints: endpoints,
|
|
|
|
Nodes: nodes,
|
|
|
|
}
|
|
|
|
}
|