Documentation ¶
Overview ¶
Package http provides a vine rpc to http proxy
Package http provides a vine rpc to http proxy
Index ¶
- Variables
- func NewProxy(opts ...proxy.Option) proxy.Proxy
- func NewService(opts ...vine.Option) vine.Service
- func NewSingleHostProxy(url string) proxy.Proxy
- func RegisterEndpoint(rpcEp string, httpEp string) error
- func WithBackend(url string) vine.Option
- func WithRouter(r server.Router) vine.Option
- type Proxy
- type Resolver
- type Router
Constants ¶
This section is empty.
Variables ¶
var ( // The default backend DefaultBackend = "http://localhost:9090" // The default router DefaultRouter = &Router{} )
Functions ¶
func NewService ¶
NewService returns a new http proxy. It acts as a vine service and proxies to a http backend. Routes are dynamically set e.g Foo.Bar routes to /foo/bar. The default backend is http://localhost:9090. Optionally specify the backend endpoint url or the router. Also choose to register specific endpoints.
Usage:
svc := NewService( service.Name("greeter"), // Sets the default http endpoint http.WithBackend("http://localhost:10001"), )
Set fixed backend endpoints
// register an endpoint http.RegisterEndpoint("Hello.World", "/helloworld") svc := NewService( service.Name("greeter"), // Set the http endpoint http.WithBackend("http://localhost:10001"), )
func NewSingleHostProxy ¶
NewSingleHostProxy returns a router which sends requests to a single http backend
func RegisterEndpoint ¶
RegisterEndpoint registers a http endpoint against an RPC endpoint
RegisterEndpoint("Foo.Bar", "/foo/bar") RegisterEndpoint("Greeter.Hello", "/helloworld") RegisterEndpoint("Greeter.Hello", "http://localhost:8080/")
func WithBackend ¶
WithBackend provides an option to set the http backend url
Types ¶
type Proxy ¶
type Proxy struct { // The http backend to call Endpoint string // contains filtered or unexported fields }
Proxy will proxy rpc requests as http POST requests. It is a server.Proxy
func (*Proxy) ProcessMessage ¶
ProcessMessage handles incoming asynchronous messages
func (*Proxy) ServeRequest ¶
ServeRequest honours the server.Router interface
type Resolver ¶
type Resolver struct{}
Resolver resolves rpc to http. It explicity maps Foo.Bar to /foo/bar
type Router ¶
type Router struct { // Converts RPC Foo.Bar to /foo/bar Resolver *Resolver // The http backend to call Backend string // contains filtered or unexported fields }
Router will proxy rpc requests as http POST requests. It is a server.Router
func NewSingleHostRouter ¶
NewSingleHostRouter returns a router which sends requests a single http backend
It is used by setting it in a new vine service to act as a proxy for a http backend.
Usage:
Create a new router to the http backend
r := NewSingleHostRouter("http://localhost:10001") // Add additional routes r.RegisterEndpoint("Hello.World", "/helloworld") // Create your new service svc := service.NewService( service.Name("greeter"), // Set the router http.WithRouter(r), ) // Run the service service.Run()
func (*Router) Endpoint ¶
Endpoint returns the http endpoint for an rpc endpoint. Endpoint("Foo.Bar") returns http://localhost:9090/foo/bar
func (*Router) ProcessMessage ¶
func (*Router) RegisterEndpoint ¶
RegisterEndpoint registers a http endpoint against an RPC endpoint. It converts relative paths into backend:endpoint. Anything prefixed with http:// or https:// will be left as is.
RegisterEndpoint("Foo.Bar", "/foo/bar") RegisterEndpoint("Greeter.Hello", "/helloworld") RegisterEndpoint("Greeter.Hello", "http://localhost:8080/")