Skip to content
Snippets Groups Projects
Commit 59dd9a01 authored by xujianhai666's avatar xujianhai666
Browse files

move some to internal

parent 940fd4ea
No related branches found
No related tags found
No related merge requests found
......@@ -18,28 +18,19 @@ limitations under the License.
package grpc
import (
//"context"
"reflect"
"testing"
)
import (
"github.com/bmizerany/assert"
"google.golang.org/grpc"
)
import (
"github.com/apache/dubbo-go/protocol/grpc/internal"
)
//type GrpcGreeterImpl struct {
// SayHello func(ctx context.Context, in *internal.HelloRequest, out *internal.HelloReply) error
//}
//
//func (u *GrpcGreeterImpl) Reference() string {
// return "GrpcGreeterImpl"
//}
//
//func (u *GrpcGreeterImpl) GetDubboStub(cc *grpc.ClientConn) internal.GreeterClient {
// return internal.NewGreeterClient(cc)
//}
func TestGetInvoker(t *testing.T) {
var conn *grpc.ClientConn
var impl *internal.GrpcGreeterImpl
......
......@@ -33,44 +33,44 @@ import (
"github.com/apache/dubbo-go/protocol/invocation"
)
// userd grpc-dubbo biz service
func addService() {
config.SetProviderService(NewGreeterProvider())
}
type GreeterProvider struct {
*GreeterProviderBase
type greeterProvider struct {
*greeterProviderBase
}
func NewGreeterProvider() *GreeterProvider {
return &GreeterProvider{
GreeterProviderBase: &GreeterProviderBase{},
func NewGreeterProvider() *greeterProvider {
return &greeterProvider{
greeterProviderBase: &greeterProviderBase{},
}
}
func (g *GreeterProvider) SayHello(ctx context.Context, req *internal.HelloRequest) (reply *internal.HelloReply, err error) {
func (g *greeterProvider) SayHello(ctx context.Context, req *internal.HelloRequest) (reply *internal.HelloReply, err error) {
fmt.Printf("req: %v", req)
return &internal.HelloReply{Message: "this is message from reply"}, nil
}
func (g *GreeterProvider) Reference() string {
func (g *greeterProvider) Reference() string {
return "GrpcGreeterImpl"
}
// code generated by greeter.go
type GreeterProviderBase struct {
type greeterProviderBase struct {
proxyImpl protocol.Invoker
}
func (g *GreeterProviderBase) SetProxyImpl(impl protocol.Invoker) {
func (g *greeterProviderBase) SetProxyImpl(impl protocol.Invoker) {
g.proxyImpl = impl
}
func (g *GreeterProviderBase) GetProxyImpl() protocol.Invoker {
func (g *greeterProviderBase) GetProxyImpl() protocol.Invoker {
return g.proxyImpl
}
func (g *GreeterProviderBase) ServiceDesc() *native_grpc.ServiceDesc {
func (g *greeterProviderBase) ServiceDesc() *native_grpc.ServiceDesc {
return &native_grpc.ServiceDesc{
ServiceName: "helloworld.Greeter",
HandlerType: (*internal.GreeterServer)(nil),
......
......@@ -19,15 +19,12 @@ package grpc
import (
"context"
"log"
"net"
"testing"
"time"
)
import (
"github.com/stretchr/testify/assert"
native_grpc "google.golang.org/grpc"
)
import (
......@@ -65,33 +62,8 @@ func TestGrpcProtocol_Export(t *testing.T) {
assert.False(t, ok)
}
// server is used to implement helloworld.GreeterServer.
type server struct {
internal.UnimplementedGreeterServer
}
// SayHello implements helloworld.GreeterServer
func (s *server) SayHello(ctx context.Context, in *internal.HelloRequest) (*internal.HelloReply, error) {
log.Printf("Received: %v", in.GetName())
return &internal.HelloReply{Message: "Hello " + in.GetName()}, nil
}
func initGrpcServer() {
port := ":20000"
lis, err := net.Listen("tcp", port)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := native_grpc.NewServer()
internal.RegisterGreeterServer(s, &server{})
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}
func TestGrpcProtocol_Refer(t *testing.T) {
go initGrpcServer()
go internal.InitGrpcServer()
time.Sleep(time.Second)
proto := GetProtocol()
......
......@@ -25,6 +25,7 @@ import (
"google.golang.org/grpc"
)
// used for dubbo-grpc biz client
type GrpcGreeterImpl struct {
SayHello func(ctx context.Context, in *HelloRequest, out *HelloReply) error
}
......
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package internal
import (
"context"
"log"
"net"
)
import (
"google.golang.org/grpc"
)
// server is used to implement helloworld.GreeterServer.
type server struct {
UnimplementedGreeterServer
}
// SayHello implements helloworld.GreeterServer
func (s *server) SayHello(ctx context.Context, in *HelloRequest) (*HelloReply, error) {
log.Printf("Received: %v", in.GetName())
return &HelloReply{Message: "Hello " + in.GetName()}, nil
}
func InitGrpcServer() {
port := ":20000"
lis, err := net.Listen("tcp", port)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
RegisterGreeterServer(s, &server{})
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment