github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/network/resolver/registry/registry.go (about) 1 // Licensed under the Apache License, Version 2.0 (the "License"); 2 // you may not use this file except in compliance with the License. 3 // You may obtain a copy of the License at 4 // 5 // https://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, 9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 // See the License for the specific language governing permissions and 11 // limitations under the License. 12 // 13 // Original source: github.com/micro/go-micro/v3/network/resolver/registry/registry.go 14 15 // Package registry resolves names using the go-micro registry 16 package registry 17 18 import ( 19 "github.com/tickoalcantara12/micro/v3/service/network/resolver" 20 "github.com/tickoalcantara12/micro/v3/service/registry" 21 "github.com/tickoalcantara12/micro/v3/service/registry/memory" 22 ) 23 24 // Resolver is a registry network resolver 25 type Resolver struct { 26 // Registry is the registry to use otherwise we use the defaul 27 Registry registry.Registry 28 } 29 30 // Resolve assumes ID is a domain name e.g micro.mu 31 func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) { 32 reg := r.Registry 33 if reg == nil { 34 reg = memory.NewRegistry() 35 } 36 37 services, err := reg.GetService(name) 38 if err != nil { 39 return nil, err 40 } 41 42 var records []*resolver.Record 43 44 for _, service := range services { 45 for _, node := range service.Nodes { 46 records = append(records, &resolver.Record{ 47 Address: node.Address, 48 }) 49 } 50 } 51 52 return records, nil 53 }