generated from pkg/go-template
36 lines
723 B
Go
36 lines
723 B
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
"git.icechen.cn/pkg/go-template/pkg/proto/example_service"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/reflection"
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
|
"log"
|
|
"net"
|
|
)
|
|
|
|
func RpcServer() {
|
|
lis, err := net.Listen("tcp", ":3000")
|
|
if err != nil {
|
|
log.Fatalf("failed to listen: %v", err)
|
|
}
|
|
|
|
s := grpc.NewServer()
|
|
example_service.RegisterUserServer(s, &Server{})
|
|
|
|
reflection.Register(s)
|
|
if err := s.Serve(lis); err != nil {
|
|
log.Fatalf("failed to serve: %v", err)
|
|
}
|
|
}
|
|
|
|
type Server struct {
|
|
}
|
|
|
|
func (s *Server) SayHello(ctx context.Context, empty *emptypb.Empty) (*example_service.UserInfo, error) {
|
|
return &example_service.UserInfo{
|
|
Name: "icechen",
|
|
}, nil
|
|
}
|