xgrpc

package module
v0.0.0-...-f582d75 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2019 License: MIT Imports: 7 Imported by: 0

README

xgrpc

grpc connection manager, especially for kit factory

Ref: https://github.com/go-kit/kit/blob/master/examples/apigateway/main.go#L184

Example


var m =xgrpc.NewManager()

func gRpcFactory(instance string) (endpoint.Endpoint, io.Closer, error) {

	// get Conn
	conn, err := m.GetConn(context.Background(),instance)
	if err != nil {
		return nil, nil, err
	}
	
	// get gRpcConn & closer
	gRpcConn, closer, err:=conn.Get(context.Background())
	if err != nil {
		return nil, nil, err
	}

	// ...
	// make endpoint

	return endpoint, closer, nil
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnNotReady = errors.New("conn is not ready")
	ErrConnClosed   = errors.New("conn is closed")
)
View Source
var (
	ErrManagerClosed = errors.New("manager is closed")
)

Functions

This section is empty.

Types

type Conn

type Conn interface {
	Get(ctx context.Context) (*grpc.ClientConn, io.Closer, error)
	Close() error
	IsClosed() bool
}

Conn is a interface because the default implementation is that there is only one connection for an address, but for some special cases, you may need an address with a connection pool.

func NewDefaultConn

func NewDefaultConn(addr string, dialFunc DialFunc) Conn

type ConnFunc

type ConnFunc func(addr string, dialFunc DialFunc) Conn

type DialFunc

type DialFunc func(ctx context.Context, addr string) (*grpc.ClientConn, error)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manage a Conn for an address

func NewManager

func NewManager(opts ...ManagerOption) *Manager

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) GetConn

func (m *Manager) GetConn(ctx context.Context, addr string) (conn Conn, err error)

type ManagerOption

type ManagerOption func(options *managerOptions)

func WithConnFunc

func WithConnFunc(connFunc ConnFunc) ManagerOption

func WithDialFunc

func WithDialFunc(dialFunc DialFunc) ManagerOption

Jump to

Keyboard shortcuts

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