package main

import (
	"context"
	"log"
	"net"

	"git.loafle.net/odds_crawler/odds-crawler-proto/network"
	"google.golang.org/grpc"
)

// server is used to implement helloworld.GreeterServer.
type server struct{}

// SayHello implements helloworld.GreeterServer
func (s *server) SayHello(ctx context.Context, in *network.NetworkRequest) (*network.NetworkReply, error) {
	log.Printf("Received: %v", in.Name)
	return &network.NetworkReply{Message: "Hello " + in.Name}, nil
}

func main() {
	lis, err := net.Listen("tcp", ":50051")
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	s := grpc.NewServer()
	network.RegisterNetworkerServer(s, &server{})
	if err := s.Serve(lis); err != nil {
		log.Fatalf("failed to serve: %v", err)
	}
}
