2019-06-03 20:44:43 +03:00
|
|
|
// Package resolver resolves a http request to an endpoint
|
2021-10-02 19:55:07 +03:00
|
|
|
package resolver // import "go.unistack.org/micro/v3/api/resolver"
|
2019-06-03 20:44:43 +03:00
|
|
|
|
|
|
|
import (
|
2020-04-03 11:18:30 +03:00
|
|
|
"errors"
|
2019-06-03 20:44:43 +03:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2020-04-03 11:18:30 +03:00
|
|
|
var (
|
2020-11-03 01:08:23 +03:00
|
|
|
// ErrNotFound returned when endpoint is not found
|
|
|
|
ErrNotFound = errors.New("not found")
|
|
|
|
// ErrInvalidPath returned on invalid path
|
2020-04-03 11:18:30 +03:00
|
|
|
ErrInvalidPath = errors.New("invalid path")
|
|
|
|
)
|
|
|
|
|
2019-06-03 20:44:43 +03:00
|
|
|
// Resolver resolves requests to endpoints
|
|
|
|
type Resolver interface {
|
2020-06-29 18:37:45 +03:00
|
|
|
Resolve(r *http.Request, opts ...ResolveOption) (*Endpoint, error)
|
2019-06-03 20:44:43 +03:00
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Endpoint is the endpoint for a http request
|
|
|
|
type Endpoint struct {
|
2020-11-03 01:08:23 +03:00
|
|
|
// Endpoint name e.g greeter
|
2019-06-03 20:44:43 +03:00
|
|
|
Name string
|
|
|
|
// HTTP Host e.g example.com
|
|
|
|
Host string
|
|
|
|
// HTTP Methods e.g GET, POST
|
|
|
|
Method string
|
|
|
|
// HTTP Path e.g /greeter.
|
|
|
|
Path string
|
2020-06-26 16:28:18 +03:00
|
|
|
// Domain endpoint exists within
|
|
|
|
Domain string
|
2020-04-09 13:03:33 +03:00
|
|
|
}
|