clientutil

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: Apache-2.0 Imports: 25 Imported by: 3

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = time.Minute
)

Variables

View Source
var (
	OK       int32 = 0
	StatusOK int32 = stdhttp.StatusOK
)

Functions

func CheckHTTPResponse added in v0.0.21

func CheckHTTPResponse(httpCode int, response Response) *errors.Error

func CheckHTTPStatus added in v0.0.21

func CheckHTTPStatus(statusCode int) *errors.Error

func CheckResponseCode added in v0.0.21

func CheckResponseCode(response Response) *errors.Error

func CheckResponseStatus added in v0.0.21

func CheckResponseStatus(resp Response) *errors.Error

func NewPingGRPCClient

func NewPingGRPCClient(serviceAPIManager ServiceAPIManager, rewriteServiceName ...ServiceName) (pingservicev1.SrvPingClient, error)

NewPingGRPCClient ...

func NewPingHTTPClient

func NewPingHTTPClient(serviceAPIManager ServiceAPIManager, rewriteServiceName ...ServiceName) (pingservicev1.SrvPingHTTPClient, error)

NewPingHTTPClient ...

Types

type Config

type Config struct {
	ServiceName   string                                   // 服务名称
	TransportType configpb.TransportTypeEnum_TransportType // 传输协议:http、grpc、...;默认: HTTP
	RegistryType  configpb.RegistryTypeEnum_RegistryType   // 注册类型:注册类型:endpoint、consul、...;配置中心配置:${registry_type};例: Bootstrap.Consul
	ServiceTarget string                                   // 服务目标:endpoint或registry,例:http://127.0.0.1:8899、discovery:///${registry_endpoint}
}

Config ...

func (*Config) IsConsulRegistry

func (s *Config) IsConsulRegistry() bool

func (*Config) IsEtcdRegistry

func (s *Config) IsEtcdRegistry() bool

func (*Config) SetByPbClusterServiceApi

func (s *Config) SetByPbClusterServiceApi(cfg *configpb.ClusterServiceApi)

type GetMetadata added in v0.0.21

type GetMetadata interface {
	GetMetadata() map[string]string
}

type Option

type Option func(*option)

func WithConsulClient

func WithConsulClient(consulClient *consulapi.Client) Option

func WithEtcdClient

func WithEtcdClient(etcdClient *clientv3.Client) Option

func WithLogger

func WithLogger(logger log.Logger) Option

type Response added in v0.0.21

type Response interface {
	GetCode() int32
	GetReason() string
	GetMessage() string
}

type ServiceAPIConnection

type ServiceAPIConnection interface {
	GetTransportType() configpb.TransportTypeEnum_TransportType
	IsTransportType(tt configpb.TransportTypeEnum_TransportType) bool
	GetGRPCConnection() (*stdgrpc.ClientConn, error)
	GetHTTPClient() (*http.Client, error)
}

func NewServiceAPIConnection

func NewServiceAPIConnection(serviceAPIManager ServiceAPIManager, serviceName ServiceName) (ServiceAPIConnection, error)

func NewSingletonServiceAPIConnection

func NewSingletonServiceAPIConnection(serviceAPIManager ServiceAPIManager, serviceName ServiceName) (ServiceAPIConnection, error)

type ServiceAPIManager

type ServiceAPIManager interface {
	// RegisterServiceAPIConfigs 注册服务API,覆盖更新
	RegisterServiceAPIConfigs(apis []*Config, opts ...Option) error
	// GetServiceAPIConfig 获取服务配置
	GetServiceAPIConfig(serviceName ServiceName) (*Config, error)
	// NewAPIConnection 实例化客户端链接
	NewAPIConnection(serviceName ServiceName) (ServiceAPIConnection, error)
}

func NewServiceAPIManager

func NewServiceAPIManager(apiConfigs []*Config, opts ...Option) (ServiceAPIManager, error)

type ServiceName

type ServiceName string

ServiceName ...

const (
	PingService   ServiceName = "ping-service"
	NodeidService ServiceName = "nodeid-service"

	FeishuApi      ServiceName = "feishu-openapi"
	DingtalkApi    ServiceName = "dingtalk-openapi"
	DingtalkApiOld ServiceName = "dingtalk-openapi-old"
)

示例:仅供参考

func (ServiceName) String

func (s ServiceName) String() string

Jump to

Keyboard shortcuts

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