diff --git a/pkg/service/a_test.go b/pkg/service/a_test.go new file mode 100644 index 000000000..fbbddaee8 --- /dev/null +++ b/pkg/service/a_test.go @@ -0,0 +1,56 @@ +package service + +import ( + "crypto/tls" + "net" + "testing" + "time" +) + +func TestName1(t *testing.T) { + + tls.Client(&testConn{}, &tls.Config{}).Handshake() + + time.Sleep(time.Hour) +} + +type testConn struct { +} + +func (testConn) Read(b []byte) (n int, err error) { + panic("implement me") +} + +func (testConn) Write(b []byte) (n int, err error) { + panic("implement me") +} + +func (testConn) Close() error { + //TODO implement me + panic("implement me") +} + +func (testConn) LocalAddr() net.Addr { + //TODO implement me + panic("implement me") +} + +func (testConn) RemoteAddr() net.Addr { + //TODO implement me + panic("implement me") +} + +func (testConn) SetDeadline(t time.Time) error { + //TODO implement me + panic("implement me") +} + +func (testConn) SetReadDeadline(t time.Time) error { + //TODO implement me + panic("implement me") +} + +func (testConn) SetWriteDeadline(t time.Time) error { + //TODO implement me + panic("implement me") +} diff --git a/pkg/service/registry.go b/pkg/service/registry.go new file mode 100644 index 000000000..38a4575ac --- /dev/null +++ b/pkg/service/registry.go @@ -0,0 +1,67 @@ +package service + +import ( + "context" + "fmt" + + "google.golang.org/grpc" +) + +type Conn interface { + GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]grpc.ClientConnInterface, error) //1 + GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (grpc.ClientConnInterface, error) //2 + GetSelfConnTarget() string //3 + AddOption(opts ...grpc.DialOption) //4 + CloseConn(conn *grpc.ClientConn) //5 + // do not use this method for call rpc +} +type SvcDiscoveryRegistry interface { + Conn + Register(serviceName, host string, port int, opts ...grpc.DialOption) error //6 + UnRegister() error //7 + Close() + GetUserIdHashGatewayHost(ctx context.Context, userId string) (string, error) // +} + +var _ SvcDiscoveryRegistry = (*DiscoveryRegistry)(nil) + +type DiscoveryRegistry struct { +} + +func (x *DiscoveryRegistry) RegisterService(desc *grpc.ServiceDesc, impl any) { + fmt.Println("RegisterService", desc, impl) +} + +func (x *DiscoveryRegistry) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]grpc.ClientConnInterface, error) { + //TODO implement me + panic("implement me") +} + +func (x *DiscoveryRegistry) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (grpc.ClientConnInterface, error) { + //TODO implement me + panic("implement me") +} + +func (x *DiscoveryRegistry) GetSelfConnTarget() string { + return "" +} + +func (x *DiscoveryRegistry) AddOption(opts ...grpc.DialOption) {} + +func (x *DiscoveryRegistry) CloseConn(conn *grpc.ClientConn) { + _ = conn.Close() +} + +func (x *DiscoveryRegistry) Register(serviceName, host string, port int, opts ...grpc.DialOption) error { + return nil +} + +func (x *DiscoveryRegistry) UnRegister() error { + return nil +} + +func (x *DiscoveryRegistry) Close() {} + +func (x *DiscoveryRegistry) GetUserIdHashGatewayHost(ctx context.Context, userId string) (string, error) { + return "", nil +} diff --git a/pkg/service/service.go b/pkg/service/service.go new file mode 100644 index 000000000..183aa4b9c --- /dev/null +++ b/pkg/service/service.go @@ -0,0 +1,14 @@ +package service + +import ( + "fmt" + + "google.golang.org/grpc" +) + +type GrpcServer struct { +} + +func (x *GrpcServer) RegisterService(desc *grpc.ServiceDesc, impl any) { + fmt.Println("RegisterService", desc, impl) +}