microlite

package module
v0.0.0-...-0436fc7 Latest Latest
Warning

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

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

README

go-micro-lite

go-micro 简化版本,只支持grpc一种协议

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultSelector = selector.NewSelector()
	DefaultRegistry = mdns.NewRegistry()
	DefaultClient   = cgrpc.NewClient()
	DefaultServer   = sgrpc.NewServer()
)
View Source
var (
	HeaderPrefix = "Micro-Lite-"
)

Functions

func NewContext

func NewContext(ctx context.Context, s Service) context.Context

NewContext returns a new Context with the Service embedded within it.

func RegisterHandler

func RegisterHandler(s server.Server, h interface{}, opts ...server.HandlerOption) error

RegisterHandler is syntactic sugar for registering a handler

Types

type Option

type Option func(*Options)

func Address

func Address(addr string) Option

Address sets the address of the server

func AfterStart

func AfterStart(fn func() error) Option

func AfterStop

func AfterStop(fn func() error) Option

func BeforeStart

func BeforeStart(fn func() error) Option

func BeforeStop

func BeforeStop(fn func() error) Option

func Broker

func Broker(b broker.Broker) Option

func Client

func Client(c client.Client) Option

func Context

func Context(ctx context.Context) Option

Context specifies a context for the service. Can be used to signal shutdown of the service. Can be used for extra option values.

func Metadata

func Metadata(md map[string]string) Option

Metadata associated with the service

func Name

func Name(n string) Option

Name of the service

func RegisterInterval

func RegisterInterval(t time.Duration) Option

RegisterInterval specifies the interval on which to re-register

func RegisterTTL

func RegisterTTL(t time.Duration) Option

RegisterTTL specifies the TTL to use when registering the service

func Registry

func Registry(r registry.Registry) Option

Registry sets the registry for the service and the underlying components

func Selector

func Selector(s selector.Selector) Option

Selector sets the selector for the service client

func Server

func Server(s server.Server) Option

func Version

func Version(v string) Option

Version of the service

func WrapCall

func WrapCall(w ...client.CallWrapper) Option

WrapCall is a convenience method for wrapping a Client CallFunc

func WrapClient

func WrapClient(w ...client.Wrapper) Option

WrapClient is a convenience method for wrapping a Client with some middleware component. A list of wrappers can be provided. Wrappers are applied in reverse order so the last is executed first.

func WrapHandler

func WrapHandler(w ...server.HandlerWrapper) Option

WrapHandler adds a handler Wrapper to a list of options passed into the server

type Options

type Options struct {
	Broker   broker.Broker
	Client   client.Client
	Server   server.Server
	Registry registry.Registry
	Selector selector.Selector

	// Before and After funcs
	BeforeStart []func() error
	BeforeStop  []func() error
	AfterStart  []func() error
	AfterStop   []func() error

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Service

type Service interface {
	Init(...Option)
	Options() Options
	Client() client.Client
	Server() server.Server
	Run() error
	String() string
}

Service is an interface that wraps the lower level libraries within go-micro. Its a convenience method for building and initialising services.

func FromContext

func FromContext(ctx context.Context) (Service, bool)

FromContext retrieves a Service from the Context.

func NewService

func NewService(opts ...Option) Service

NewService creates and returns a new Service based on the packages within.

Directories

Path Synopsis
api
handler
Package handler provides http handlers
Package handler provides http handlers
handler/api
Package api provides an http-rpc handler which provides the entire http request over rpc
Package api provides an http-rpc handler which provides the entire http request over rpc
handler/broker
Package broker provides a go-micro/broker handler
Package broker provides a go-micro/broker handler
handler/cloudevents
Package cloudevents provides a cloudevents handler publishing the event using the go-micro/client
Package cloudevents provides a cloudevents handler publishing the event using the go-micro/client
handler/event
Package event provides a handler which publishes an event
Package event provides a handler which publishes an event
handler/file
Package file serves file relative to the current directory
Package file serves file relative to the current directory
handler/http
Package http is a http reverse proxy handler
Package http is a http reverse proxy handler
handler/registry
Package registry is a go-micro/registry handler
Package registry is a go-micro/registry handler
handler/rpc
Package rpc is a go-micro rpc handler.
Package rpc is a go-micro rpc handler.
handler/udp
Package udp reads and write from a udp connection
Package udp reads and write from a udp connection
handler/unix
Package unix reads from a unix socket expecting it to be in /tmp/path
Package unix reads from a unix socket expecting it to be in /tmp/path
handler/web
Package web contains the web handler including websocket support
Package web contains the web handler including websocket support
proto
Package go_api is a generated protocol buffer package.
Package go_api is a generated protocol buffer package.
resolver
Package resolver resolves a http request to an endpoint
Package resolver resolves a http request to an endpoint
resolver/grpc
Package grpc resolves a grpc service like /greeter.Say/Hello to greeter service
Package grpc resolves a grpc service like /greeter.Say/Hello to greeter service
router
Package router provides api service routing
Package router provides api service routing
router/registry
Package registry provides a dynamic api service router
Package registry provides a dynamic api service router
server
Package server provides an API gateway server which handles inbound requests
Package server provides an API gateway server which handles inbound requests
server/acme
Package acme abstracts away various ACME libraries
Package acme abstracts away various ACME libraries
server/acme/autocert
Package autocert is the ACME provider from golang.org/x/crypto/acme/autocert This provider does not take any config.
Package autocert is the ACME provider from golang.org/x/crypto/acme/autocert This provider does not take any config.
server/http
Package http provides a http server with features; acme, cors, etc
Package http provides a http server with features; acme, cors, etc
Package client is an interface for an RPC client
Package client is an interface for an RPC client
grpc
Package grpc provides a gRPC client Package grpc provides a gRPC options
Package grpc provides a gRPC client Package grpc provides a gRPC options
rpc
Package rpc provides an rpc client
Package rpc provides an rpc client
Package errors provides a way to return detailed information for an RPC request error.
Package errors provides a way to return detailed information for an RPC request error.
examples
api
greeter/api/rpc/proto/hello
Package go_micro_api_greeter is a generated protocol buffer package.
Package go_micro_api_greeter is a generated protocol buffer package.
greeter/proto
Package go_micro_srv_greeter is a generated protocol buffer package.
Package go_micro_srv_greeter is a generated protocol buffer package.
service/proto
Package greeter is a generated protocol buffer package.
Package greeter is a generated protocol buffer package.
stream/server/proto
Package stream is a generated protocol buffer package.
Package stream is a generated protocol buffer package.
libs
net
tls
Package metadata is a way of defining message headers
Package metadata is a way of defining message headers
Package registry is an interface for service discovery
Package registry is an interface for service discovery
mdns
Package mdns is a multicast dns registry
Package mdns is a multicast dns registry
Package selector is a way to pick a list of service nodes
Package selector is a way to pick a list of service nodes
dns
Package dns provides a dns SRV selector
Package dns provides a dns SRV selector
registry
Package registry uses the go-micro registry for selection
Package registry uses the go-micro registry for selection
static
Package static provides a static resolver which returns the name/ip passed in without any change
Package static provides a static resolver which returns the name/ip passed in without any change
Package server is an interface for a micro server
Package server is an interface for a micro server
debug/proto
Package debug is a generated protocol buffer package.
Package debug is a generated protocol buffer package.
grpc
Package grpc provides a grpc server
Package grpc provides a grpc server
rpc
Package rpc provides an rpc server
Package rpc provides an rpc server

Jump to

Keyboard shortcuts

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