http

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package http provides a micro rpc to http proxy

Index

Constants

This section is empty.

Variables

View Source
var (
	// The default backend
	DefaultBackend = "http://localhost:9090"
	// The default router
	DefaultRouter = &Router{}
)

Functions

func NewService

func NewService(opts ...micro.Option) micro.Service

NewService returns a new http proxy. It acts as a micro service proxy. Any request on the transport is routed to a fixed http backend.

Usage:

service := NewService(
	micro.Name("greeter"),
	// Sets the default http endpoint
	http.WithBackend("http://localhost:10001"),
 )

func WithBackend

func WithBackend(url string) micro.Option

WithBackend provides an option to set the http backend url

func WithRouter

func WithRouter(r server.Router) micro.Option

WithRouter provides an option to set the http router

Types

type Router

type Router struct {
	// 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

func NewSingleHostRouter(url string) *Router

NewSingleHostRouter returns a router which sends requests to 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")

// Create your new service
service := micro.NewService(
	micro.Name("greeter"),
	// Set the router
	http.WithRouter(r),
)

// Run the service
service.Run()

func (*Router) ServeRequest

func (p *Router) ServeRequest(ctx context.Context, req server.Request, rsp server.Response) error

ServeRequest honours the server.Router interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL