github.com/btccom/go-micro/v2@v2.9.3/api/resolver/grpc/grpc.go (about) 1 // Package grpc resolves a grpc service like /greeter.Say/Hello to greeter service 2 package grpc 3 4 import ( 5 "errors" 6 "net/http" 7 "strings" 8 9 "github.com/btccom/go-micro/v2/api/resolver" 10 ) 11 12 type Resolver struct{} 13 14 func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { 15 // /foo.Bar/Service 16 if req.URL.Path == "/" { 17 return nil, errors.New("unknown name") 18 } 19 // [foo.Bar, Service] 20 parts := strings.Split(req.URL.Path[1:], "/") 21 // [foo, Bar] 22 name := strings.Split(parts[0], ".") 23 // foo 24 return &resolver.Endpoint{ 25 Name: strings.Join(name[:len(name)-1], "."), 26 Host: req.Host, 27 Method: req.Method, 28 Path: req.URL.Path, 29 }, nil 30 } 31 32 func (r *Resolver) String() string { 33 return "grpc" 34 } 35 36 func NewResolver(opts ...resolver.Option) resolver.Resolver { 37 return &Resolver{} 38 }