gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/api/resolver/path/path.go (about)

     1  // Package path resolves using http path
     2  package path
     3  
     4  import (
     5  	"errors"
     6  	"net/http"
     7  	"strings"
     8  
     9  	"gitee.com/liuxuezhan/go-micro-v1.18.0/api/resolver"
    10  )
    11  
    12  type Resolver struct{}
    13  
    14  func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) {
    15  	if req.URL.Path == "/" {
    16  		return nil, errors.New("unknown name")
    17  	}
    18  	parts := strings.Split(req.URL.Path[1:], "/")
    19  	return &resolver.Endpoint{
    20  		Name:   parts[0],
    21  		Host:   req.Host,
    22  		Method: req.Method,
    23  		Path:   req.URL.Path,
    24  	}, nil
    25  }
    26  
    27  func (r *Resolver) String() string {
    28  	return "path"
    29  }
    30  
    31  func NewResolver(opts ...resolver.Option) resolver.Resolver {
    32  	return &Resolver{}
    33  }