qgrpc

package
v0.0.0-...-35fa672 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: MIT Imports: 19 Imported by: 21

Documentation

Index

Constants

View Source
const (
	DefaultSchema = "default"
)
View Source
const (
	MetaKey = "meta"
)

Variables

View Source
var (
	ErrNoSuchGrpcClient = errors.New("no such grpc client")
	ErrConf             = errors.New("conf error")
)
View Source
var (
	ErrInvalidLengthQgrpc        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowQgrpc          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupQgrpc = fmt.Errorf("proto: unexpected end of group")
)

Functions

func Call

func Call(ctx context.Context, method string, args, reply interface{}) (err error)

func CallIn100ms

func CallIn100ms(ctx context.Context, method string, args, reply interface{}) (err error)

100ms超时

func CallIn200ms

func CallIn200ms(ctx context.Context, method string, args, reply interface{}) (err error)

func CallIn500ms

func CallIn500ms(ctx context.Context, method string, args, reply interface{}) (err error)

func CallWithOption

func CallWithOption(ctx context.Context, conn *grpc.ClientConn, method string, args, reply interface{}, opts ...grpc.CallOption) (err error)

method->/rpc.Rpc/Ping

func CallWithServerName

func CallWithServerName(ctx context.Context, serverName, method string, args, reply interface{}) (err error)

func CallWithServerNameTimeout

func CallWithServerNameTimeout(ctx context.Context, serverName, method string, args, reply interface{}, t time.Duration) (err error)

func CallWithTimeout

func CallWithTimeout(ctx context.Context, method string, args, reply interface{}, t time.Duration) (err error)

func GetConn

func GetConn(name string) *grpc.ClientConn

根据server-name 获得对应的连接池

func GetEtcdClient

func GetEtcdClient() *qetcd.Op

func GetListenerKey

func GetListenerKey(serverName string) string

func GetRegisterKey

func GetRegisterKey(key string) string

func GetRegisterServerNames

func GetRegisterServerNames() []string

func GetRegisterValue

func GetRegisterValue() string

func Init

func Init(c *Config) error

初始化

Types

type Config

type Config struct {
	// etcd的地址 必须要
	Endpoints []string `toml:"endpoints" json:"endpoints"`
	// etcd的服务的前缀,需要通过prefix来区别正式测试等等环境 必须要
	Prefix string `toml:"prefix" json:"prefix"`

	// 注册部分
	// 服务名称,固定为 aa.Aa ,grpc的服务名称,如果服务多个,可以用 | 来分割
	ServerName string `toml:"serverName" json:"server_name"`
	// 你注册的服务地址,可以是外网地址,也可以是内网地址
	Addr string `toml:"addr" json:"addr"`
	// 额外存储的部分
	Ext string `toml:"ext" json:"ext"`

	Schema string `toml:"schema" json:"schema"`

	// 监听部分
	// 想要监听的服务地址
	// 用grpc做lb
	WatchServers []string `toml:"watchServers" json:"watch_servers"`

	// 这种就是默认全监听,收到之后,相当于每个服务,会单独的去监听
	// 适合长连接的类型,不需要lb的这种
	WatchPrefix []string `toml:"watchPrefix" json:"watch_prefix"`

	// 是否阻塞启动
	Block bool `toml:"block"`
}

etcd的配置

type GrpcClient

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

type NoArgs

type NoArgs struct {
}

func (*NoArgs) Descriptor

func (*NoArgs) Descriptor() ([]byte, []int)

func (*NoArgs) Marshal

func (m *NoArgs) Marshal() (dAtA []byte, err error)

func (*NoArgs) MarshalTo

func (m *NoArgs) MarshalTo(dAtA []byte) (int, error)

func (*NoArgs) MarshalToSizedBuffer

func (m *NoArgs) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*NoArgs) ProtoMessage

func (*NoArgs) ProtoMessage()

func (*NoArgs) Reset

func (m *NoArgs) Reset()

func (*NoArgs) Size

func (m *NoArgs) Size() (n int)

func (*NoArgs) String

func (m *NoArgs) String() string

func (*NoArgs) Unmarshal

func (m *NoArgs) Unmarshal(dAtA []byte) error

func (*NoArgs) XXX_DiscardUnknown

func (m *NoArgs) XXX_DiscardUnknown()

func (*NoArgs) XXX_Marshal

func (m *NoArgs) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*NoArgs) XXX_Merge

func (m *NoArgs) XXX_Merge(src proto.Message)

func (*NoArgs) XXX_Size

func (m *NoArgs) XXX_Size() int

func (*NoArgs) XXX_Unmarshal

func (m *NoArgs) XXX_Unmarshal(b []byte) error

type Op

type Op struct {

	// 配置文件
	C *Config
	// 本地的地址
	LocalIp string
	// contains filtered or unexported fields
}
var (
	O *Op
)

func (*Op) AddGrpcClient

func (o *Op) AddGrpcClient(serverName string, target *RegisterModel, w *watcher) error

func (*Op) DeleteGrpcClient

func (o *Op) DeleteGrpcClient(serverName string)

type RegisterModel

type RegisterModel struct {
	Name      string `json:"name,omitempty"`
	CreatedAt string `json:"created_at,omitempty"`
	Addr      string `json:"addr,omitempty"`
	Hostname  string `json:"hostname,omitempty"`
	Ext       string `json:"ext,omitempty"`
}

func ExtractRegisterModel

func ExtractRegisterModel(val string) *RegisterModel

func GetPrefixAddrsRegisterModel

func GetPrefixAddrsRegisterModel(serviceName string) []*RegisterModel

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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