Documentation
¶
Overview ¶
Package http provides a micro to http proxy
Index ¶
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 micro 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:
service := NewService(
micro.Name("greeter"),
// Sets the default http endpoint
http.WithBackend("http://localhost:10001"),
)
Set fixed backend endpoints
// register an endpoint
http.RegisterEndpoint("Hello.World", "/helloworld")
service := NewService(
micro.Name("greeter"),
// Set the http endpoint
http.WithBackend("http://localhost:10001"),
)
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 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 micro 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
service := micro.NewService(
micro.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/")
Source Files
¶
- http.go
- options.go