|
|
@ -59,6 +59,10 @@ func (s *Server) Stop() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *Server) build() error {
|
|
|
|
func (s *Server) build() error {
|
|
|
|
|
|
|
|
if err := s.ensureUpstreamNames(); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return mr.MapReduceVoid(func(source chan<- interface{}) {
|
|
|
|
return mr.MapReduceVoid(func(source chan<- interface{}) {
|
|
|
|
for _, up := range s.upstreams {
|
|
|
|
for _, up := range s.upstreams {
|
|
|
|
source <- up
|
|
|
|
source <- up
|
|
|
@ -68,13 +72,13 @@ func (s *Server) build() error {
|
|
|
|
cli := zrpc.MustNewClient(up.Grpc)
|
|
|
|
cli := zrpc.MustNewClient(up.Grpc)
|
|
|
|
source, err := s.createDescriptorSource(cli, up)
|
|
|
|
source, err := s.createDescriptorSource(cli, up)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
cancel(err)
|
|
|
|
cancel(fmt.Errorf("%s: %w", up.Name, err))
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
methods, err := internal.GetMethods(source)
|
|
|
|
methods, err := internal.GetMethods(source)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
cancel(err)
|
|
|
|
cancel(fmt.Errorf("%s: %w", up.Name, err))
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -95,7 +99,7 @@ func (s *Server) build() error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, m := range up.Mappings {
|
|
|
|
for _, m := range up.Mappings {
|
|
|
|
if _, ok := methodSet[m.RpcPath]; !ok {
|
|
|
|
if _, ok := methodSet[m.RpcPath]; !ok {
|
|
|
|
cancel(fmt.Errorf("rpc method %s not found", m.RpcPath))
|
|
|
|
cancel(fmt.Errorf("%s: rpc method %s not found", up.Name, m.RpcPath))
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -162,6 +166,19 @@ func (s *Server) createDescriptorSource(cli zrpc.Client, up Upstream) (grpcurl.D
|
|
|
|
return source, nil
|
|
|
|
return source, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *Server) ensureUpstreamNames() error {
|
|
|
|
|
|
|
|
for _, up := range s.upstreams {
|
|
|
|
|
|
|
|
target, err := up.Grpc.BuildTarget()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
up.Name = target
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *Server) prepareMetadata(header http.Header) []string {
|
|
|
|
func (s *Server) prepareMetadata(header http.Header) []string {
|
|
|
|
vals := internal.ProcessHeaders(header)
|
|
|
|
vals := internal.ProcessHeaders(header)
|
|
|
|
if s.processHeader != nil {
|
|
|
|
if s.processHeader != nil {
|
|
|
|