edb/api.go

37 lines
963 B
Go
Raw Permalink 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) {
2020-03-05 10:10:40 +00:00
return &goproto.Reply{Msg: "Hello " + in.What, Status: 1, Content: []string{"dasasdasdas"}}, nil
2020-03-04 21:12:38 +00:00
}
// SayHello implements
2020-03-05 10:10:40 +00:00
func (s *server) CreateTable(ctx context.Context, in *goproto.TableRequest) (*goproto.Reply, error) {
return &goproto.Reply{Msg: "Create Table " + in.Name, Status: 1, Content: []string{"dasasdasdas"}}, nil
2020-03-04 21:21:29 +00:00
}
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
}