package main import ( "context" "fmt" pb "go-rpc/rpc" "log" "net" "google.golang.org/grpc" ) type NodeServer struct { } func (s *NodeServer) GetNode(ctx context.Context, req *pb.NodeRequest) (*pb.NodeResponse, error) { log.Println(" [x] Received request", req) if req.Name == "special" { return &pb.NodeResponse{}, nil } return &pb.NodeResponse{ Name: "Test Node", Email: "test@no-reply.net", Address: &pb.Address{ City: &pb.City{ Name: "Gliwice", PostalCode: "44-122", }, Street: "Testowa", Number: 1, Apartment: 1, }, }, nil } func (s *NodeServer) SayHello(ctx context.Context, req *pb.Message) (*pb.Message, error) { return &pb.Message{ Content: "You said: " + req.Content, }, nil } func main() { port := ":50500" lis, err := net.Listen("tcp", fmt.Sprintf(port)) if err != nil { log.Fatalf(" [x] Failed to listen: %v\n", err) } log.Printf(" [x] Listening on %s\n", port) s := grpc.NewServer() pb.RegisterNodeServiceServer(s, &NodeServer{}) // reflection.Register(s) s.Serve(lis) }