common

package
v0.0.0-...-f274578 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TIMEOUT_KEY = "timeout"
)

Variables

View Source
var (
	// grpc options
	GRPC_KeepAliveTime         = time.Duration(10) * time.Second
	GRPC_KeepAliveTimeout      = time.Duration(3) * time.Second
	GRPC_BackoffMaxDelay       = time.Duration(3) * time.Second
	GRPC_MaxSendMsgSize        = 1 << 24
	GRPC_MaxCallMsgSize        = 1 << 24
	GRPC_InitialWindowSize     = 1 << 30
	GRPC_InitialConnWindowSize = 1 << 30
)

Functions

func Trans2HumanRate

func Trans2HumanRate(rate int64) int64

TransRate trans the rate to multiples of 1000,the production of rate should be division by 1000.

Types

type GrpcClientConfig

type GrpcClientConfig struct {
	Scheme           string //resovler-scheme
	RootName         string //服务名1 -- 对应registry:RegistyNodeKey
	SvcName          string //服务名2 -- 对应registry:ServiceName
	MetaToken        string //客户端认证
	RegistyType      string //服务发现方法	consul/etcdv2/etcdv3
	RegistryAddrs    string //服务注册地址
	ResovleScheme    string //reslover-名字
	LoadBalancerName string //负载均衡方法
	TlsCommonName    string //
	TlsCertPath      string
	KeepAliveTtlOn   bool //keep-live on

	//OPENTracing配置
	Tracer     opentracing.Tracer //服务tracer
	TracerAddr string             //服务tracer-地址
	TracerType string             //tracer类型(zipkin|jaeger)

	//METAINFO认证
	AuthType          string //auth-basic(http标准认证)|APPID+APPSECKEY
	AccessToken       string //服务认证票据|AppSeckey
	AppID             string
	AuthRpcCredential WrapperPerRPCCredentials //notice this is a interface{}

	//客户端重试选项
	RetryOn       bool          //重试开关
	RetryInterval time.Duration //重试间隔
	RetryMax      int           //重试次数
	RetryTimeout  time.Duration //重试超时时间

}

type GrpcServerConfig

type GrpcServerConfig struct {
	RootName      string //服务名1
	SvcName       string //服务名
	BindAddr      string //服务地址
	Port          int
	NodeId        string //服务节点
	RegistryAddrs string //服务注册地址

	//OPENTracing配置
	Tracer     opentracing.Tracer //服务tracer
	TracerAddr string             //服务tracer-地址
	TracerType string             //tracer类型(zipkin|jaeger)

	//METAINFO认证
	AuthType    string //auth-basic(http标准认证)|APPID+APPSECKEY
	AccessToken string //服务认证票据
	AppID       string
}

type RPCCredential

type RPCCredential struct {
	ServiceToken   string
	AppId          string
	CredentialType string
}

this struct will be inject into metainfo

func (*RPCCredential) GetRequestMetadata

func (c *RPCCredential) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)

func (*RPCCredential) RequireTransportSecurity

func (c *RPCCredential) RequireTransportSecurity() bool

func (*RPCCredential) SetServiceToken

func (c *RPCCredential) SetServiceToken(token string)

interface{} 和 struct{} 通信

func (*RPCCredential) SetServiceTokenType

func (c *RPCCredential) SetServiceTokenType(tokentype string)

type RateLimiter

type RateLimiter interface {
	//阻塞获取 tokens
	AcquireTokensWithBlock(ctx context.Context, token int64) int64

	//阻塞获取 tokens,最大超时时间为ctx定义的时间
	AcquireTokensWithNonBlock(ctx context.Context, token int64) int64
}

type RegistyNodeValue

type RegistyNodeValue struct {
	Addr     string //IP:port
	Weight   int
	Metadata map[string]string
}

注册到KV系统中的VALUE 1. ETCD -- value 2. consul -- tags

type RegistyOptions

type RegistyOptions struct {
	Endpoints   string //注册地址
	RootName    string //
	ServiceName string
	NodeUniqID  string
	NodeValue   RegistyNodeValue
	Interval    time.Duration
	Address     string
	Port        int
	UserName    string //`yaml:"user_name"`
	Pass        string //`yaml:"pass"`
}

注册到KV系统中的VALUE 1. ETCD -- 同类型的前缀(以ServiceName区分) /RootName/ServiceName/uniqid 2. consul -- 相同的ServiceName,但要求NodeUniqID必须唯一(长度限制)

type ResolverOptions

type ResolverOptions struct {
	Endpoints   string //注册地址
	RootName    string
	ServiceName string
	//EtcdPrefixKey = /RootName/ServiceName
	Scheme   string
	UserName string //`yaml:"user_name"`
	Pass     string //`yaml:"pass"`
}

type WrapperPerRPCCredentials

type WrapperPerRPCCredentials interface {
	GetRequestMetadata(context.Context, ...string) (map[string]string, error)
	RequireTransportSecurity() bool
	SetServiceToken(string)
	SetServiceTokenType(string)
}

Jump to

Keyboard shortcuts

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