github.com/btccom/go-micro/v2@v2.9.3/api/resolver/path/path.go (about) 1 // Package path resolves using http path 2 package path 3 4 import ( 5 "net/http" 6 "strings" 7 8 "github.com/btccom/go-micro/v2/api/resolver" 9 ) 10 11 type Resolver struct { 12 opts resolver.Options 13 } 14 15 func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { 16 if req.URL.Path == "/" { 17 return nil, resolver.ErrNotFound 18 } 19 20 parts := strings.Split(req.URL.Path[1:], "/") 21 ns := r.opts.Namespace(req) 22 23 return &resolver.Endpoint{ 24 Name: ns + "." + parts[0], 25 Host: req.Host, 26 Method: req.Method, 27 Path: req.URL.Path, 28 }, nil 29 } 30 31 func (r *Resolver) String() string { 32 return "path" 33 } 34 35 func NewResolver(opts ...resolver.Option) resolver.Resolver { 36 return &Resolver{opts: resolver.NewOptions(opts...)} 37 }