micro

package module
v0.0.0-...-625ea8d Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

README

v-micro

Build Status codecov

可插拔的微服务框架(参考 go-micro)

起源

起源及开 v-micro 的原因,见 doc/intro.md

改进

依赖

  • go1.12 +

编译

  • Windows 编译

    make build
    
  • Linux 编译

    ./make.sh build
    

例子

  • hello ,入门例子
  • protobuf ,protobuf 协议生成例子
  • flags ,命令行参数例子
  • registry ,服务发现例子
  • echo ,回显测试
  • broadcast ,广播消息例子
  • metadata ,客户端元数据、服务器端元数据例子
  • filter ,过滤器例子
  • wrapper ,客户端、服务器端包装器例子

基准测试

TODO

  • Registry 新增插件: consul
  • Transport 新增插件: http
  • 吞吐量测试,性能报告
  • 更多的例子
  • 更多的测试、单元测试
  • 回显测试性能优化
    • RPC 过程中减少分配内存,参考官方 RPC 实现

贡献

代码很大一部分来源于 go-micro ,太多,不再一一注释说明。特此声明

Documentation

Overview

Package micro is a pluggable framework for microservices

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHandler

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

RegisterHandler is syntactic sugar for registering a handler

Types

type Option

type Option func(*Options)

Option option

func Action

func Action(a func(*cli.Context)) Option

Action action

func Address

func Address(addr string) Option

Address sets the address of the server

func AfterStart

func AfterStart(fn func() error) Option

AfterStart AfterStart

func AfterStop

func AfterStop(fn func() error) Option

AfterStop AfterStop

func BeforeStart

func BeforeStart(fn func() error) Option

BeforeStart BeforeStart

func BeforeStop

func BeforeStop(fn func() error) Option

BeforeStop BeforeStop

func Client

func Client(c client.Client) Option

Client client

func Connector

func Connector(ct connector.Connector) Option

Connector sets the connector for the service client

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 Flags

func Flags(flags ...cli.Flag) Option

Flags flags

func Logger

func Logger(l log.Logger) Option

Logger logger

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

Server server

func Transport

func Transport(t transport.Transport) Option

Transport sets the transport for the service and the underlying components

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 {
	Logger    log.Logger
	Client    client.Client
	Server    server.Server
	Registry  registry.Registry
	Transport transport.Transport

	// Flags and Action
	Flags  []cli.Flag
	Action func(*cli.Context)

	// 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
}

Options options

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 v-micro. Its a convenience method for building and initialising services.

func NewService

func NewService(opts ...Option) Service

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

Directories

Path Synopsis
Package client is an interface for an RPC client
Package client is an interface for an RPC client
rpc
Package codec is an interface for encoding messages
Package codec is an interface for encoding messages
proto
Package proto provides a proto codec
Package proto provides a proto codec
common
log
Package log is a global internal logger
Package log is a global internal logger
metadata
Package metadata is a way of defining message headers
Package metadata is a way of defining message headers
examples
internal
net
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
cache
Package cache provides a registry cache
Package cache provides a registry cache
Package server is an interface for a micro server
Package server is an interface for a micro server
rpc

Jump to

Keyboard shortcuts

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