edb/api.go

37 lines
881 B
Go
Raw Normal View History

2020-03-04 10:09:19 +00:00
package main
import (
context "context"
2020-03-04 21:21:29 +00:00
"edb/goproto"
"log"
"net"
grpc "google.golang.org/grpc"
2020-03-04 10:09:19 +00:00
)
// server is used to implement
type server struct{}
// SayHello implements
2020-03-04 21:21:29 +00:00
func (s *server) SayHello(ctx context.Context, in *goproto.Request) (*goproto.Reply, error) {
return &goproto.Reply{Msg: "Hello " + in.GetWhat()}, nil
2020-03-04 21:12:38 +00:00
}
// SayHello implements
2020-03-04 21:21:29 +00:00
func (s *server) CreateTable(ctx context.Context, in *goproto.TableRequest) (*goproto.TableReply, error) {
return &goproto.TableReply{Msg: "Hello " + in.Name}, nil
}
func createTestServer() {
//起服务
listen, err := net.Listen("tcp", "localhost:"+port)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
gserver := grpc.NewServer()
goproto.RegisterEasyDataServer(gserver, &server{})
goproto.RegisterTestServer(gserver, &server{})
log.Println("create test service : ", port)
gserver.Serve(listen)
2020-03-04 10:09:19 +00:00
}