service

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

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

Go to latest
Published: Sep 27, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Etcd      string = "etcd"
	Consul           = "consul"
	Zookeeper        = "zookeeper"
)

Variables

View Source
var File_service_proto protoreflect.FileDescriptor
View Source
var Greeter_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "helloworld.Greeter",
	HandlerType: (*GreeterServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "SayHello",
			Handler:    _Greeter_SayHello_Handler,
		},
		{
			MethodName: "SayHelloAgain",
			Handler:    _Greeter_SayHelloAgain_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "service.proto",
}

Greeter_ServiceDesc is the grpc.ServiceDesc for Greeter service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func RegisterGreeterServer

func RegisterGreeterServer(s grpc.ServiceRegistrar, srv GreeterServer)

Types

type BaseClient

type BaseClient struct {
	Addr string
	Conn *grpc.ClientConn
}

func NewBaseClient

func NewBaseClient(addr string) *BaseClient

func (*BaseClient) Close

func (bc *BaseClient) Close()

func (*BaseClient) Dial

func (bc *BaseClient) Dial(opts ...grpc.DialOption)

func (*BaseClient) SetAddr

func (bc *BaseClient) SetAddr(addr string)

type BaseService

type BaseService struct {
	IRegistry
	IRPCServerImpl
	IRPCClientImpl

	Index      string
	Name       string
	Typ        string
	IP         string
	BasePrefix string

	Cfgs sync.Map // serviceID-key-value
}

func NewBaseService

func NewBaseService(typ, index, name string, registry IRegistry, server IRPCServerImpl, client IRPCClientImpl) *BaseService

func (*BaseService) GetCfgByTyp

func (s *BaseService) GetCfgByTyp(typ string) (res []map[string]string)

GetCfgByTyp 返回一个res切片,切片的索引是 typ 类型的service的索引,切片元素是service的配置

func (*BaseService) GetIP

func (s *BaseService) GetIP() string

func (*BaseService) GetName

func (s *BaseService) GetName() string

func (*BaseService) GetType

func (s *BaseService) GetType() string

func (*BaseService) ID

func (s *BaseService) ID() string

func (*BaseService) Init

func (s *BaseService) Init()

func (*BaseService) Register

func (s *BaseService) Register()

Register 必须在s.IRegistry.Init()后调用

func (*BaseService) SetBasePrefix

func (s *BaseService) SetBasePrefix(prefix string)

func (*BaseService) Start

func (s *BaseService) Start()

func (*BaseService) Stop

func (s *BaseService) Stop()

func (*BaseService) Sync

func (s *BaseService) Sync()

Sync 必须在s.IRegistry.Init()后调用

func (*BaseService) Watch

func (s *BaseService) Watch()

func (*BaseService) WrapPrefix

func (s *BaseService) WrapPrefix() string

type EtcdRegistry

type EtcdRegistry struct {
	ReqTimeout time.Duration
	LeaseTTL   int64 // time-to-live in seconds
	Typ        string
	Endpoints  []string

	Cfg *clientv3.Config
	Cli *clientv3.Client
}

func NewEtcdRegistry

func NewEtcdRegistry(cfg *clientv3.Config, timeout time.Duration, ttl int64) *EtcdRegistry

func (*EtcdRegistry) Delete

func (e *EtcdRegistry) Delete(key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error)

func (*EtcdRegistry) Get

func (e *EtcdRegistry) Get(key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error)

func (*EtcdRegistry) GetType

func (e *EtcdRegistry) GetType() string

func (*EtcdRegistry) Init

func (e *EtcdRegistry) Init()

func (*EtcdRegistry) Put

func (e *EtcdRegistry) Put(key, value string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error)

func (*EtcdRegistry) Register

func (e *EtcdRegistry) Register(prefix string, kvs interface{})

func (*EtcdRegistry) Stop

func (e *EtcdRegistry) Stop()

func (*EtcdRegistry) Watch

func (e *EtcdRegistry) Watch(key string, opts ...clientv3.OpOption) clientv3.WatchChan

func (*EtcdRegistry) WatchCallBack

func (e *EtcdRegistry) WatchCallBack(watchChan clientv3.WatchChan, fn etcd_v3.WatchCallback)

type GreeterClient

type GreeterClient interface {
	// Sends a greeting
	SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error)
	SayHelloAgain(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error)
}

GreeterClient is the client API for Greeter service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewGreeterClient

func NewGreeterClient(cc grpc.ClientConnInterface) GreeterClient

type GreeterClientImpl

type GreeterClientImpl struct {
	*BaseClient

	Cli     GreeterClient
	Timeout time.Duration
}

func (*GreeterClientImpl) Close

func (gc *GreeterClientImpl) Close()

func (*GreeterClientImpl) Dial

func (gc *GreeterClientImpl) Dial(opts ...grpc.DialOption)

func (*GreeterClientImpl) Do

func (gc *GreeterClientImpl) Do()

type GreeterServer

type GreeterServer interface {
	// Sends a greeting
	SayHello(context.Context, *HelloRequest) (*HelloReply, error)
	SayHelloAgain(context.Context, *HelloRequest) (*HelloReply, error)
	// contains filtered or unexported methods
}

GreeterServer is the server API for Greeter service. All implementations must embed UnimplementedGreeterServer for forward compatibility

type GreeterServiceImpl

type GreeterServiceImpl struct {
	UnimplementedGreeterServer

	Addr string
}

GreeterServiceImpl is used to implement GreeterServer.

func (*GreeterServiceImpl) GetAddr

func (s *GreeterServiceImpl) GetAddr() string

func (*GreeterServiceImpl) SayHello

func (s *GreeterServiceImpl) SayHello(ctx context.Context, in *HelloRequest) (*HelloReply, error)

SayHello implements GreeterServer

func (*GreeterServiceImpl) SayHelloAgain

func (s *GreeterServiceImpl) SayHelloAgain(ctx context.Context, in *HelloRequest) (*HelloReply, error)

func (*GreeterServiceImpl) Serve

func (s *GreeterServiceImpl) Serve()

type HelloReply

type HelloReply struct {
	Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
	// contains filtered or unexported fields
}

The response message containing the greetings

func (*HelloReply) Descriptor deprecated

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

Deprecated: Use HelloReply.ProtoReflect.Descriptor instead.

func (*HelloReply) GetMessage

func (x *HelloReply) GetMessage() string

func (*HelloReply) ProtoMessage

func (*HelloReply) ProtoMessage()

func (*HelloReply) ProtoReflect

func (x *HelloReply) ProtoReflect() protoreflect.Message

func (*HelloReply) Reset

func (x *HelloReply) Reset()

func (*HelloReply) String

func (x *HelloReply) String() string

type HelloRequest

type HelloRequest struct {
	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	// contains filtered or unexported fields
}

The request message containing the user's name.

func (*HelloRequest) Descriptor deprecated

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

Deprecated: Use HelloRequest.ProtoReflect.Descriptor instead.

func (*HelloRequest) GetName

func (x *HelloRequest) GetName() string

func (*HelloRequest) ProtoMessage

func (*HelloRequest) ProtoMessage()

func (*HelloRequest) ProtoReflect

func (x *HelloRequest) ProtoReflect() protoreflect.Message

func (*HelloRequest) Reset

func (x *HelloRequest) Reset()

func (*HelloRequest) String

func (x *HelloRequest) String() string

type IRPCClientImpl

type IRPCClientImpl interface {
	Close()
	Dial(...grpc.DialOption)
	SetAddr(string)
}

type IRPCServerImpl

type IRPCServerImpl interface {
	Serve()
	GetAddr() string
}

type IRegistry

type IRegistry interface {
	Init()
	Stop()
	GetType() string
	Register(string, interface{})
}

type IService

type IService interface {
	Init()
	Start()
	Stop()
	Register()
	Sync()
}

type UnimplementedGreeterServer

type UnimplementedGreeterServer struct {
}

UnimplementedGreeterServer must be embedded to have forward compatible implementations.

func (UnimplementedGreeterServer) SayHello

func (UnimplementedGreeterServer) SayHelloAgain

type UnsafeGreeterServer

type UnsafeGreeterServer interface {
	// contains filtered or unexported methods
}

UnsafeGreeterServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to GreeterServer will result in compilation errors.

Jump to

Keyboard shortcuts

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