github.com/annwntech/go-micro/v2@v2.9.5/api/resolver/resolver.go (about)

     1  // Package resolver resolves a http request to an endpoint
     2  package resolver
     3  
     4  import (
     5  	"errors"
     6  	"net/http"
     7  )
     8  
     9  var (
    10  	ErrNotFound    = errors.New("not found")
    11  	ErrInvalidPath = errors.New("invalid path")
    12  )
    13  
    14  // Resolver resolves requests to endpoints
    15  type Resolver interface {
    16  	Resolve(r *http.Request, opts ...ResolveOption) (*Endpoint, error)
    17  	String() string
    18  }
    19  
    20  // Endpoint is the endpoint for a http request
    21  type Endpoint struct {
    22  	// e.g greeter
    23  	Name string
    24  	// HTTP Host e.g example.com
    25  	Host string
    26  	// HTTP Methods e.g GET, POST
    27  	Method string
    28  	// HTTP Path e.g /greeter.
    29  	Path string
    30  	// Domain endpoint exists within
    31  	Domain string
    32  }
    33  
    34  // StaticNamespace returns the same namespace for each request
    35  func StaticNamespace(ns string) func(*http.Request) string {
    36  	return func(*http.Request) string {
    37  		return ns
    38  	}
    39  }